Skip to content

Commit 886eefd

Browse files
committed
internal/core/adt: fix closedness bug
It is incorrect to assume that if a close builtin is used within a definition, it no longer needs to be marked as closed. For instance, locally, it may be unified with another field that is illegal. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I6d05b551593eda115a86d0309fd1accd2ed101b0 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172013 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 145764d commit 886eefd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cue/testdata/comprehensions/issue293.txtar

+13-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ t: p: "foo"
2828
-- variant1.cue --
2929
#V1: {
3030
x: close({ f1: int })
31-
x: f2: 2 // TODO: fail
31+
x: f2: 2
3232
}
3333
-- out/eval/stats --
3434
Leaks: 3
@@ -42,6 +42,9 @@ Conjuncts: 33
4242
Disjuncts: 20
4343
-- out/eval --
4444
Errors:
45+
#V1.x.f2: field not allowed:
46+
./variant1.cue:2:11
47+
./variant1.cue:3:5
4548
z.x.f2: field not allowed:
4649
./in.cue:2:2
4750
./in.cue:5:12
@@ -76,10 +79,16 @@ Result:
7679
#C: (#struct){
7780
p: (_){ _ }
7881
}
79-
#V1: (#struct){
80-
x: (#struct){
82+
#V1: (_|_){
83+
// [eval]
84+
x: (_|_){
85+
// [eval]
8186
f1: (int){ int }
82-
f2: (int){ 2 }
87+
f2: (_|_){
88+
// [eval] #V1.x.f2: field not allowed:
89+
// ./variant1.cue:2:11
90+
// ./variant1.cue:3:5
91+
}
8392
}
8493
}
8594
}

internal/core/compile/builtin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var closeBuiltin = &adt.Builtin{
8686
if !ok {
8787
return c.NewErrf("struct argument must be concrete")
8888
}
89-
if m, ok := s.BaseValue.(*adt.StructMarker); ok && m.NeedClose || s.Closed {
89+
if m, ok := s.BaseValue.(*adt.StructMarker); ok && m.NeedClose {
9090
return s
9191
}
9292
v := s.Clone()

0 commit comments

Comments
 (0)