-- in.cue --
import mystrings "strings"

@foo(bar)

p1: [X=string]: name: X

d1: "foo\(bar)": int
bar: "bar"

d2: C="foo\(bar)": {
	name: "xx"
	foo:  C.name
}

// Issue #1910
a: _
comp: {
	for k, v in [0]
	let w = v {
		"\(a)": w
		"\(bar)": w
	}
}

bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'

c1: mystrings.Contains("aa", "a")

s1: """
    multi
    \(bar)
    line
    """

l1: [3, ...int]
l2: [...int]
l3: []
l4: [1, 2]
l5: [1, 3] & {
	[1, 3]

	#foo: int
}

#foo: int
l6: [1, #foo] & {
	[1, 3]

	#foo: int
}

n1:  1.0
n10: 10

// Ignored comment.

// t is true
t: true

// Dangling comment.

e1:  <n1
e2:  >n1 & <n10
e3:  l4[2]
e4:  l4[2:3]
e5:  e1 + e2 - e3
e6:  !t
e7:  !t || !false
e8?: !false

m1: {[string]: uint} & {
	// this is a pattern constraint
	{[string]: int} & {[string]: int64}

	// foo is an optional field
	foo?: 3

	// Dangling comment.

	// bar is a field
	bar: 4

	// baz is a required field.
	baz!: 5

	// a comment too many.

	...
}

if true {
	x: int
}

y1: {
	src: [1, 2, 3]
	for i, v in src for j, w in src if i < j {
		"foo\(i)": v
		"bar\(j)": w
	}

	for i, v in src {
		"foo\(i)": v
	}

	x: [
		for x in src
		let y = x {
			y
		},
	]
}

preserveKeyFieldInComprehension: {
	for _, s in [1] {
		s
	}
}

errorStructDef: {
	a: 1
	b: 1 & 2

	#Def: 1
}

errorList: [
	1,
	1 & 2,
]

errorListDef: {
	errorList

	#Def: 1
}
-- out/definition --
import mystrings "strings"

@foo(bar)
p1: {
	[X=string]: {
		name: X
	}
}
d1: {
	"foobar": int
}
bar: "bar"
d2: {
	C="foobar": {
		name: "xx"
		foo:  C.name
	}
}

// Issue #1910
a: _
comp: {
	for k, v in [0]
	let w = v {
		"\(a)": w
		"bar":  w
	}
}
bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
c1:    mystrings.Contains("aa", "a")
s1:    """
		multi
		\(bar)
		line
		"""
l1: [3, ...int]
l2: [...int]
l3: []
l4: [1, 2]
l5: [1, 3] & {
	[1, 3]
	#foo: int
}
#foo: int
l6: [1, #foo] & {
	[1, 3]
	#foo: int
}
n1:  1.0
n10: 10

// t is true
t:   true
e1:  <n1
e2:  >n1 & <n10
e3:  l4[2]
e4:  l4[2:3]
e5:  e1 + e2 - e3
e6:  !t
e7:  !t || !false
e8?: !false
m1: {
	[string]: uint
} & {
	{
		[string]: int
	} & {
		[string]: int64
	}

	// foo is an optional field
	foo?: 3

	// bar is a field
	bar: 4

	// baz is a required field.
	baz!: 5
	...
}

if true {
	x: int
}
y1: {
	src: [1, 2, 3]
	for i, v in src for j, w in src if i < j {
		"foo\(i)": v
		"bar\(j)": w
	}

	for i, v in src {
		"foo\(i)": v
	}
	x: [
		for x in src
		let y = x {
			y
		}]
}
preserveKeyFieldInComprehension: {
	for _, s in [1] {
		s
	}
}
errorStructDef: {
	a:    1
	b:    _|_ // conflicting values 2 and 1
	#Def: 1
}
errorList: [1, 1 & 2]
errorListDef: {
	errorList
	#Def: 1
}
-- diff/doc/explanation --
Reordering.
-- out/doc --
[]
[p1]
[d1]
[d1 foobar]
[bar]
[d2]
[d2 foobar]
[d2 foobar name]
[d2 foobar foo]
[a]
- Issue #1910

[comp]
[comp bar]
[bytes]
[c1]
[s1]
[l1]
[l1 0]
[l2]
[l3]
[l4]
[l4 0]
[l4 1]
[l5]
[l5 #foo]
[l5 0]
[l5 1]
[#foo]
[l6]
[l6 #foo]
[l6 0]
[l6 1]
[n1]
[n10]
[t]
- t is true

[e1]
[e2]
[e3]
[e4]
[e5]
[e6]
[e7]
[e8]
[m1]
[m1 foo]
- foo is an optional field

[m1 bar]
- bar is a field

[m1 baz]
- baz is a required field.

[x]
[y1]
[y1 src]
[y1 src 0]
[y1 src 1]
[y1 src 2]
[y1 x]
[y1 x 0]
[y1 x 1]
[y1 x 2]
[y1 foo0]
[y1 bar1]
[y1 bar2]
[y1 foo1]
[y1 foo2]
[preserveKeyFieldInComprehension]
[errorStructDef]
[errorStructDef a]
[errorStructDef b]
[errorStructDef #Def]
[errorList]
[errorList 0]
[errorList 1]
[errorListDef]
[errorListDef #Def]
[errorListDef 0]
[errorListDef 1]
-- out/value --
== Simplified
_|_ // e3: index out of range [2] with length 2
== Raw
_|_ // e3: index out of range [2] with length 2
== Final
_|_ // e3: index out of range [2] with length 2
== All
{
	@foo(bar)
	x: int
	p1: {}
	d1: {
		foobar: int
	}
	bar: "bar"
	d2: {
		foobar: {
			name: "xx"
			foo:  "xx"
		}
	}

	// Issue #1910
	a: _
	comp: {
		for k, v in [0]
		let w = v {
			"\(a)": w
			"bar":  w
		}
	}
	bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
	c1:    true
	s1: """
		multi
		bar
		line
		"""
	l1: [3, ...int]
	l2: [...int]
	l3: []
	l4: [1, 2]
	l5: {
		#foo: int
		[1, 3]
	}
	#foo: int
	l6: {
		#foo: int
		[1, 3]
	}
	n1:  1.0
	n10: 10

	// t is true
	t:   true
	e1:  <1.0
	e2:  >1.0 & <10
	e3:  _|_ // e3: index out of range [2] with length 2
	e4:  _|_ // e4: index 3 out of range
	e5:  _|_ // e3: index out of range [2] with length 2
	e6:  false
	e7:  true
	e8?: true
	m1: {
		// foo is an optional field
		foo?: 3

		// bar is a field
		bar: 4

		// baz is a required field.
		baz!: 5
	}
	y1: {
		foo0: 1
		bar1: 2
		bar2: 3
		foo1: 2
		foo2: 3
		src: [1, 2, 3]
		x: [1, 2, 3]
	}
	preserveKeyFieldInComprehension: 1
	errorStructDef: {
		a:    1
		b:    _|_ // errorStructDef.b: conflicting values 2 and 1
		#Def: 1
	}
	errorList: [1, _|_]
	errorListDef: {
		#Def: 1
		[1, _|_]
	}
}
== Eval
_|_ // e3: index out of range [2] with length 2
