-- issue3635.cue --
import "list"
// evalv3: `incDependent: already closed` panic with a builtin and a disjunction;
// using list.Concat to satisfy a disjunction of map or list should not crash.
// https://cuelang.org/issue/3635
issue3635: case1: {
	Run: {
		env: *{[string]: string} | [...string]
	}

	command: Run & {
		env: list.Concat([["foo"], ["bar"]])
	}
	@test(eq, {
		Run: {env: *{} | []}
		command: {env: ["foo", "bar"]}
	})
}

issue3635: case2: {
	out: [...#Schema]
	out: [#Schema & {
		name: "x"
	}]

	#Schema: {
		name?: string
		container?: [string]: string | #container

		#container: string | {
			env?: #env
		}

		#env: [string]: bool | string
	}
	@test(eq, {
		out: [{
			name: "x"
			container?: {}
			#container: string | {env?: {}}
			#env: [string]: bool | string
		}]
		#Schema: {
			name?: string
			container?: {}
			#container: string | {env?: {}}
			#env: [string]: bool | string

		}
	})
}

issue3635: reduced: {
	out: {X} & X
	X: {
		b: int | c
		c: int | { e: d }
	}
	d: 1
	@test(eq, {
		out: {b: int | {e: 1}, c: int | {e: 1}}
		X: {b: int | {e: 1}, c: int | {e: 1}}
		d: 1
	})
}

issue3635: reduced_noshare: {
	out: {X} & X
	X: {
		b: int | c
		c: int | { e: d & __no_sharing }
	}
	d: 1
	@test(eq, {
		out: {b: int | {e: 1}, c: int | {e: 1}}
		X: {b: int | {e: 1}, c: int | {e: 1}}
		d: 1
	})
}
-- out/eval/stats --
Leaks:  7
Freed:  81
Reused: 66
Allocs: 22
Retain: 0

Unifications: 52
Conjuncts:    118
Disjuncts:    32

NumCloseIDs: 19
