Skip to content

Commit 6916b5b

Browse files
committed
internal/core/adt: hoist allows from injectClosed
The code currently used matchPattern directly in processComprehesionInner, which really should use allows. Hoist the code so it can be shared. We do so in a separate CL to keep no-op changes separated from material ones. We'll fix the bug in a followup CL. Issue #3486 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I02f743898e33c8e6fdd03fccfc9080a9b63535de Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202420 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 89acced commit 6916b5b

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

internal/core/adt/fields.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,11 @@ func isTotal(p Value) bool {
957957
// and patterns defined in closed. It reports an error in the nodeContext if
958958
// this is not the case.
959959
func injectClosed(ctx *OpContext, closed, dst *closeContext) {
960-
// TODO: check that fields are not void arcs.
961-
outer:
962960
for _, a := range dst.arcs {
963961
if a.kind != ARC {
964962
continue
965963
}
966964
ca := a.cc
967-
f := ca.Label()
968965
if ca.arcType == ArcPending {
969966
// This happens when a comprehension did not yield any results.
970967
continue
@@ -980,26 +977,12 @@ outer:
980977
default:
981978
panic("unreachable")
982979
}
980+
f := ca.Label()
983981
// TODO: disallow new definitions in closed structs.
984982
if f.IsHidden() || f.IsLet() || f.IsDef() {
985983
continue
986984
}
987-
for _, b := range closed.arcs {
988-
cb := b.cc
989-
// TODO: we could potentially remove the check for ArcPending if we
990-
// explicitly set the arcType to ArcNonPresent when a comprehension
991-
// yields no results.
992-
if cb.arcType == ArcNotPresent || cb.arcType == ArcPending {
993-
continue
994-
}
995-
if f == cb.Label() {
996-
continue outer
997-
}
998-
}
999-
if !matchPattern(ctx, closed.Expr, ca.Label()) {
1000-
ctx.notAllowedError(closed.src, ca.src)
1001-
continue
1002-
}
985+
closed.allows(ctx, f, ca)
1003986
}
1004987

1005988
if !dst.isClosed {
@@ -1015,6 +998,26 @@ outer:
1015998
}
1016999
}
10171000

1001+
func (c *closeContext) allows(ctx *OpContext, f Feature, ca *closeContext) bool {
1002+
for _, b := range c.arcs {
1003+
cb := b.cc
1004+
// TODO: we could potentially remove the check for ArcPending if we
1005+
// explicitly set the arcType to ArcNonPresent when a comprehension
1006+
// yields no results.
1007+
if cb.arcType == ArcNotPresent || cb.arcType == ArcPending {
1008+
continue
1009+
}
1010+
if f == cb.Label() {
1011+
return true
1012+
}
1013+
}
1014+
if !matchPattern(ctx, c.Expr, f) {
1015+
ctx.notAllowedError(c.src, ca.src)
1016+
return false
1017+
}
1018+
return true
1019+
}
1020+
10181021
func (ctx *OpContext) addPositions(c Conjunct) {
10191022
if x, ok := c.x.(*ConjunctGroup); ok {
10201023
for _, c := range *x {

0 commit comments

Comments
 (0)