In this file we test cases where references are shadowed:
- x: x: x
- a newly created dynamic field which ends up shadowing an existing field.

-- in.cue --
shadowRef: t1: {
	x: "x": x | null
}

shadowRef: t2: {
	x: "x": "x": x | null
}

shadowRef: t3: {
	x: "x": x: "x": x | null
}

shadowRef: t4: {
	X=x: {
		x: X | null
		y: x
	}
}

shadowRef: t5: {
	X=x: x: X | null
}

shadowRef: e1: {
	x: "x": x // structural error, but should still print ok.
	x: {}
}

shadowAlias: t1: {
	y: "outer"
	a: {
		key: "y"
		X=(key): "inner"

		refs: {
			Z="y": 1
			outer: y
			mid:   X
			inner: Z

		}
	}
}

shadowAlias: t2: {
	a: {
		key: "y"
		X=(key): "inner"

		refs: {
			Z="y": 1
			outer: y
			mid:   X
			inner: Z

		}
	}
	y: "outer"
}

shadowField: t1: {
	z: {
		A=b: 0
		d: {
			b: 1
			c: A
		}
	}
}

shadowField: t2: {
	z: {
		A=b: 0
		d: {
			b: 1
			c: A
		}
	}
	z: d: { A: 1 }
}

shadowField: t4: {
	merge: {
		z: {
			A=b: 0
			d: {
				b: 1
				c: A
			}
		}
	}

	merge: {
		z: {
			A=b: 0
			d: {
				b: 1
				c: A
			}
		}
		z: d: { A: 1 }
	}
}

shadowField: t5: {
	merge: {
		A=b: 0
		d: {
			b: 1
			c: A
		}
	}
	merge: {
		b: 0
		d: b: 1
	}
}

// TODO: could be simplified to:
// 		A=b: 0
//  	c:   A
// or even
// 		b: 0
//  	c: b
shadowField: t6: {
	x: {
		A=b: 0
		c: A
	}
	x: b: 0
}

shadowField: issue2378: {
	a: {
		A=b: 0
		d: {
			b: 1
			c: A & a.z
		}
	}
}

-- out/definition --
shadowRef: {
	t1: {
		x_1=x: {
			x: x_1 | null
		}
	}
	t2: {
		x_5=x: {
			x: {
				x: x_5 | null
			}
		}
	}
	t3: {
		x: {
			x: {
				x_A=x: {
					x: x_A | null
				}
			}
		}
	}
	t4: {
		X=x: {
			x: X | null
			y: x
		}
	}
	t5: {
		X=x: {
			x: X | null
		}
	}
	e1: {
		x_8=x: {
			x: x_8
		}
	}
}
shadowAlias: {
	t1: {
		y: "outer"
		a: {
			key:     "y"
			X=(key): "inner"
			refs: {
				Z="y": 1
				outer: y
				mid:   X
				inner: Z
			}
		}
	}
	t2: {
		a: {
			key:       "y"
			X_1=(key): "inner"
			refs: {
				Z="y": 1
				outer: y
				mid:   X_1
				inner: Z
			}
		}
		y: "outer"
	}
}
shadowField: {
	t1: {
		z: {
			A=b: 0
			d: {
				b: 1
				c: A
			}
		}
	}
	t2: {
		z: {
			{
				A=b: 0
				d: {
					b: 1
					c: A
				}
			}
			d: {
				A: 1
			}
		}
	}
	t4: {
		merge: {
			z: {
				{
					A=b: 0
					d: {
						b: 1
						c: A
					}
				}
				{
					A=b: 0
					d: {
						b: 1
						c: A
					}
				}
				d: {
					A: 1
				}
			}
		}
	}
	t5: {
		merge: {
			{
				A=b: 0
				d: {
					b: 1
					c: A
				}
			}
			b: 0
			d: {
				b: 1
			}
		}
	}
	t6: {
		x: {
			{
				A=b: 0
				c:   A
			}
			b: 0
		}
	}
	issue2378: {
		a: {
			A=b: 0
			d: {
				b: 1
				c: A & a.z
			}
		}
	}
}
-- out/doc --
[]
[shadowRef]
[shadowRef t1]
[shadowRef t1 x]
[shadowRef t1 x x]
[shadowRef t2]
[shadowRef t2 x]
[shadowRef t2 x x]
[shadowRef t2 x x x]
[shadowRef t3]
[shadowRef t3 x]
[shadowRef t3 x x]
[shadowRef t3 x x x]
[shadowRef t3 x x x x]
[shadowRef t4]
[shadowRef t4 x]
[shadowRef t4 x x]
[shadowRef t4 x y]
[shadowRef t5]
[shadowRef t5 x]
[shadowRef t5 x x]
[shadowRef e1]
[shadowRef e1 x]
[shadowRef e1 x x]
[shadowAlias]
[shadowAlias t1]
[shadowAlias t1 y]
[shadowAlias t1 a]
[shadowAlias t1 a key]
[shadowAlias t1 a refs]
[shadowAlias t1 a refs y]
[shadowAlias t1 a refs outer]
[shadowAlias t1 a refs mid]
[shadowAlias t1 a refs inner]
[shadowAlias t1 a y]
[shadowAlias t2]
[shadowAlias t2 a]
[shadowAlias t2 a key]
[shadowAlias t2 a refs]
[shadowAlias t2 a refs y]
[shadowAlias t2 a refs outer]
[shadowAlias t2 a refs mid]
[shadowAlias t2 a refs inner]
[shadowAlias t2 a y]
[shadowAlias t2 y]
[shadowField]
[shadowField t1]
[shadowField t1 z]
[shadowField t1 z b]
[shadowField t1 z d]
[shadowField t1 z d b]
[shadowField t1 z d c]
[shadowField t2]
[shadowField t2 z]
[shadowField t2 z b]
[shadowField t2 z d]
[shadowField t2 z d b]
[shadowField t2 z d c]
[shadowField t2 z d A]
[shadowField t4]
[shadowField t4 merge]
[shadowField t4 merge z]
[shadowField t4 merge z b]
[shadowField t4 merge z d]
[shadowField t4 merge z d b]
[shadowField t4 merge z d c]
[shadowField t4 merge z d A]
[shadowField t5]
[shadowField t5 merge]
[shadowField t5 merge b]
[shadowField t5 merge d]
[shadowField t5 merge d b]
[shadowField t5 merge d c]
[shadowField t6]
- TODO: could be simplified to:
		A=b: 0
 	c:   A
or even
		b: 0
 	c: b

[shadowField t6 x]
[shadowField t6 x b]
[shadowField t6 x c]
[shadowField issue2378]
[shadowField issue2378 a]
[shadowField issue2378 a b]
[shadowField issue2378 a d]
[shadowField issue2378 a d b]
[shadowField issue2378 a d c]
-- out/value-v3 --
== Simplified
_|_ // shadowRef.e1.x.x: structural cycle
== Raw
_|_ // shadowRef.e1.x.x: structural cycle
== Final
_|_ // shadowRef.e1.x.x: structural cycle
== All
{
	shadowRef: {
		t1: {
			x: {
				x: null
			}
		}
		t2: {
			x: {
				x: {
					x: null
				}
			}
		}
		t3: {
			x: {
				x: {
					x: {
						x: null
					}
				}
			}
		}
		t4: {
			x: {
				x: null
				y: null
			}
		}
		t5: {
			x: {
				x: null
			}
		}
		e1: {
			x: {
				x: _|_ // shadowRef.e1.x.x: structural cycle
			}
		}
	}
	shadowAlias: {
		t1: {
			y: "outer"
			a: {
				key: "y"
				y:   "inner"
				refs: {
					y:     1
					outer: "outer"
					mid:   "inner"
					inner: 1
				}
			}
		}
		t2: {
			a: {
				key: "y"
				y:   "inner"
				refs: {
					y:     1
					outer: "outer"
					mid:   "inner"
					inner: 1
				}
			}
			y: "outer"
		}
	}
	shadowField: {
		t1: {
			z: {
				b: 0
				d: {
					b: 1
					c: 0
				}
			}
		}
		t2: {
			z: {
				b: 0
				d: {
					b: 1
					c: 0
					A: 1
				}
			}
		}
		t4: {
			merge: {
				z: {
					b: 0
					d: {
						b: 1
						c: 0
						A: 1
					}
				}
			}
		}
		t5: {
			merge: {
				b: 0
				d: {
					b: 1
					c: 0
				}
			}
		}

		// TODO: could be simplified to:
		// 		A=b: 0
		//  	c:   A
		// or even
		// 		b: 0
		//  	c: b
		t6: {
			x: {
				b: 0
				c: 0
			}
		}
		issue2378: {
			a: {
				b: 0
				d: {
					b: 1
					c: A & a.z
				}
			}
		}
	}
}
== Eval
_|_ // shadowRef.e1.x.x: structural cycle
-- diff/-out/value-v3<==>+out/value --
diff old new
--- old
+++ new
@@ -1,9 +1,9 @@
 == Simplified
-_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
+_|_ // shadowRef.e1.x.x: structural cycle
 == Raw
-_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
+_|_ // shadowRef.e1.x.x: structural cycle
 == Final
-_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
+_|_ // shadowRef.e1.x.x: structural cycle
 == All
 {
 	shadowRef: {
@@ -41,7 +41,7 @@
 		}
 		e1: {
 			x: {
-				x: _|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
+				x: _|_ // shadowRef.e1.x.x: structural cycle
 			}
 		}
 	}
@@ -139,4 +139,4 @@
 	}
 }
 == Eval
-_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
+_|_ // shadowRef.e1.x.x: structural cycle
-- out/value --
== Simplified
_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
== Raw
_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
== Final
_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
== All
{
	shadowRef: {
		t1: {
			x: {
				x: null
			}
		}
		t2: {
			x: {
				x: {
					x: null
				}
			}
		}
		t3: {
			x: {
				x: {
					x: {
						x: null
					}
				}
			}
		}
		t4: {
			x: {
				x: null
				y: null
			}
		}
		t5: {
			x: {
				x: null
			}
		}
		e1: {
			x: {
				x: _|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
			}
		}
	}
	shadowAlias: {
		t1: {
			y: "outer"
			a: {
				key: "y"
				y:   "inner"
				refs: {
					y:     1
					outer: "outer"
					mid:   "inner"
					inner: 1
				}
			}
		}
		t2: {
			a: {
				key: "y"
				y:   "inner"
				refs: {
					y:     1
					outer: "outer"
					mid:   "inner"
					inner: 1
				}
			}
			y: "outer"
		}
	}
	shadowField: {
		t1: {
			z: {
				b: 0
				d: {
					b: 1
					c: 0
				}
			}
		}
		t2: {
			z: {
				b: 0
				d: {
					b: 1
					c: 0
					A: 1
				}
			}
		}
		t4: {
			merge: {
				z: {
					b: 0
					d: {
						b: 1
						c: 0
						A: 1
					}
				}
			}
		}
		t5: {
			merge: {
				b: 0
				d: {
					b: 1
					c: 0
				}
			}
		}

		// TODO: could be simplified to:
		// 		A=b: 0
		//  	c:   A
		// or even
		// 		b: 0
		//  	c: b
		t6: {
			x: {
				b: 0
				c: 0
			}
		}
		issue2378: {
			a: {
				b: 0
				d: {
					b: 1
					c: A & a.z
				}
			}
		}
	}
}
== Eval
_|_ // shadowRef.e1.x.x: structural cycle (and 1 more errors)
