# Tests that a comprehension-generated struct merged into a list element
# constrained by a closed definition correctly rejects fields not declared
# in the definition. Fields introduced via comprehension inside a list
# literal should still be subject to closedness checks.
# Issue: https://cuelang.org/issue/153
-- in.cue --
Foo: {
	listOfCloseds: [...#Closed]
}

#Closed: {
	a: int | *0
}

Junk: {
	b: 2 @test(eq, 2)
}

Foo & {
	listOfCloseds: [{
		for k, v in Junk {
			"\(k)": v
		}
	}]
}
@test(eq, {
	Foo: listOfCloseds: []
	#Closed: a: int | *0
	Junk: b: 2
	listOfCloseds: _|_ @test(err, at=0.b, code=eval,
		hint="considerably more positions could be useful",
		contains="field not allowed", pos=[-4:4])
})
-- out/errors.txt --
[eval] listOfCloseds.0.b: field not allowed:
    ./in.cue:16:4
-- out/eval/stats --
Leaks:  0
Freed:  15
Reused: 5
Allocs: 10
Retain: 0
Unifications: 11
Conjuncts:    22
Disjuncts:    4
Notifications: 1
NumCloseIDs: 5
-- out/diff-v2-v3.txt --
missing error positions: v3 reports fewer positions than v2.
listOfCloseds.0.b: field not allowed:
-    ./in.cue:2:18
-    ./in.cue:2:21
-    ./in.cue:5:10
-    ./in.cue:13:1
-    ./in.cue:14:18
-    ./in.cue:15:3
     ./in.cue:16:4
