# Embedding a closed definition through `({} & schema).export` caused
# `json.Marshal(this)` inside `#Name` to re-enter Finalize on the
# in-flight vertex with a fresh OpContext. The typo check then ran
# against arc conjunctInfo from the original context and falsely
# reported `field not allowed` for sanctioned fields like `name`.
#
# https://cuelang.org/issue/4366
-- in.cue --
import "encoding/json"

schema: {
	$val: prefix: string | *""
	$val: prefix: "redis-"

	#Name: this={
		name: $val.prefix + (#shortHash & {in: json.Marshal(this)}).out
	}
	#shortHash: {in: string, out: ""}

	_in: #Name

	export: [
		_in,
		if _in.name != _|_ {_in},
	]
}

result: ({} & schema).export @test(eq, [
	{name: "redis-"},
	{name: "redis-"},
])
-- out/eval/stats --
Leaks:  2
Freed:  44
Reused: 27
Allocs: 19
Retain: 0

Unifications: 35
Conjuncts:    65
Disjuncts:    4

NumCloseIDs: 17
