#name: alias reuse in nested scope
#evalFull
-- in.cue --
#Foo: {
	let X = or([for k, _ in {} {k}])
	connection: [X]: X
}
#A: {
	foo: "key"
	let X = foo
	a: foo: [X]: X
}
#B: {
	foo: string
	let X = foo
	a: foo: [X]: X
}
b: #B & {foo: "key"}
-- out/def --
#Foo: {
	connection: {
		[or([for k, _ in {
				...
		} { k }])]: or([for k, _ in {
			...
		} { k }])
	}
}
#A: {
	foo: "key"
	a: {
		foo: {
			["key"]: "key"
		}
	}
}
#B: {
	foo: string
	FOO = foo
	a: {
		foo: {
			[FOO]: FOO
		}
	}
}
b: #B & {
	foo: "key"
}
-- out/export --
b: {
	foo: "key"
	a: {
		foo: {}
	}
}
-- out/yaml --
b:
  foo: key
  a:
    foo: {}
-- out/json --
{"b":{"foo":"key","a":{"foo":{}}}}
-- out/legacy-debug --
<0>{#Foo: <1>C{connection: <2>C{[or ([ <3>for k, _ in <4>{} yield <3>.k ])]: <5>(_: string)->or ([ <3>for k, _ in <4>{} yield <3>.k ]), }}, #A: <6>C{foo: "key", a: <7>C{foo: <8>C{["key"]: <9>(_: string)-><10>.foo, }}}, #B: <11>C{foo: string, a: <12>C{foo: <13>C{[string]: <14>(_: string)-><15>.foo, }}}, b: <16>C{foo: "key", a: <17>C{foo: <18>C{["key"]: <19>(_: string)-><20>.foo, }}}}
-- out/eval/stats --
Leaks:  10
Freed:  19
Reused: 15
Allocs: 14
Retain: 10

Unifications: 29
Conjuncts:    40
Disjuncts:    29
-- out/evalalpha --
(struct){
  #Foo: (#struct){
    let X#1 = (_|_){
      // [incomplete] empty list in call to or:
      //     ./in.cue:2:10
    }
    connection: (_|_){
      // [incomplete] empty list in call to or:
      //     ./in.cue:2:10
    }
  }
  #A: (#struct){
    foo: (string){ "key" }
    let X#2 = (string){ "key" }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
  #B: (#struct){
    foo: (string){ string }
    let X#3 = (string){ string }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
  b: (#struct){
    foo: (string){ "key" }
    let X#3 = (string){ "key" }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -4,7 +4,9 @@
       // [incomplete] empty list in call to or:
       //     ./in.cue:2:10
     }
-    connection: (#struct){
+    connection: (_|_){
+      // [incomplete] empty list in call to or:
+      //     ./in.cue:2:10
     }
   }
   #A: (#struct){
-- diff/explanation --
The new error is a correct error, as the pattern constraint is invalid.
Seems reasonable to report error at connection as well.
-- out/eval --
(struct){
  #Foo: (#struct){
    let X#1 = (_|_){
      // [incomplete] empty list in call to or:
      //     ./in.cue:2:10
    }
    connection: (#struct){
    }
  }
  #A: (#struct){
    foo: (string){ "key" }
    let X#2 = (string){ "key" }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
  #B: (#struct){
    foo: (string){ string }
    let X#3 = (string){ string }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
  b: (#struct){
    foo: (string){ "key" }
    let X#3 = (string){ "key" }
    a: (#struct){
      foo: (#struct){
      }
    }
  }
}
-- out/compile --
--- in.cue
{
  #Foo: {
    let X#1 = or([
      for k, _ in {} {
        〈1;k〉
      },
    ])
    connection: {
      [〈1;let X#1〉]: 〈1;let X#1〉
    }
  }
  #A: {
    foo: "key"
    let X#2 = 〈0;foo〉
    a: {
      foo: {
        [〈2;let X#2〉]: 〈2;let X#2〉
      }
    }
  }
  #B: {
    foo: string
    let X#3 = 〈0;foo〉
    a: {
      foo: {
        [〈2;let X#3〉]: 〈2;let X#3〉
      }
    }
  }
  b: (〈0;#B〉 & {
    foo: "key"
  })
}
