Skip to content

Commit f7095a9

Browse files
committed
internal/core/adt: hoist newGroup logic
We will use this call in another location later as well. Note that we chose to not generalize this function and hoist the similar logic in addResolver as well. This keeps the function simple, as there are too many differences for this to be convenient. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ic15e4f8327bc9f2ca1eb52e76c6fb43deeda291a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211933 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent c437118 commit f7095a9

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

internal/core/adt/typocheck.go

+15-20
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ func (n *nodeContext) addResolver(v *Vertex, id CloseInfo, forceIgnore bool) Clo
333333
return id
334334
}
335335

336+
func (n *nodeContext) newGroup(id CloseInfo) (CloseInfo, defID) {
337+
srcID := id.defID
338+
dstID := n.ctx.getNextDefID()
339+
n.reqDefIDs = append(n.reqDefIDs, refInfo{
340+
v: emptyNode,
341+
id: dstID,
342+
ignore: true,
343+
})
344+
id.defID = dstID
345+
n.addReplacement(replaceID{from: srcID, to: dstID, add: true})
346+
return id, dstID
347+
}
348+
336349
// AddOpenConjunct adds w as a conjunct of v and disables typo checking for w,
337350
// even if it is a definition.
338351
func (v *Vertex) AddOpenConjunct(ctx *OpContext, w *Vertex) {
@@ -379,17 +392,9 @@ func (n *nodeContext) injectEmbedNode(x Decl, id CloseInfo) CloseInfo {
379392
}
380393
}
381394

382-
dstID := n.ctx.getNextDefID()
383-
n.reqDefIDs = append(n.reqDefIDs, refInfo{
384-
v: emptyNode,
385-
id: dstID,
386-
ignore: true,
387-
})
388-
id.defID = dstID
395+
id, dstID := n.newGroup(id)
389396
id.enclosingEmbed = dstID
390397

391-
n.addReplacement(replaceID{from: srcID, to: dstID, add: true})
392-
393398
return id
394399
}
395400

@@ -422,23 +427,13 @@ func (n *nodeContext) splitDefID(s *StructLit, id CloseInfo) CloseInfo {
422427
return id
423428
}
424429

425-
srcID := id.defID
426-
427-
dstID := n.ctx.getNextDefID()
428-
n.reqDefIDs = append(n.reqDefIDs, refInfo{
429-
v: emptyNode,
430-
id: dstID,
431-
ignore: true,
432-
})
433-
id.defID = dstID
430+
id, dstID := n.newGroup(id)
434431

435432
if !id.hasOuter {
436433
id.hasOuter = true
437434
id.outerID = dstID
438435
}
439436

440-
n.addReplacement(replaceID{from: srcID, to: dstID, add: true})
441-
442437
return id
443438
}
444439

0 commit comments

Comments
 (0)