-- in.cue --
import "list"

// issue3330: out[0] is a list element that shares #A's vertex.
issue3330: {
	#A: {
		let empty = {}

		// Reference to empty is within the definition that defines it. Closedness
		// thus does not trigger.
		field: null | {n: int}
		field: empty & {n: 3}
	}

	out: list.Concat([[#A]])
}

// eliminated: ensures a definition used only for the empty struct triggers the
// disjunct-elimination code path that caused the original panic in issue3330.
eliminated: {
	#empty: {}
	x: null | {n: 3}
	x: #empty & {n: 3}
	out: len(x)
}

// simplified: different take showing the bug is triggered after a definition
// is referenced.
simplified: {
	#struct: {
		field: {n: 3} & g
		g: {}
	}

	out: #struct & {}
}
-- out/compile --
--- in.cue
{
  issue3330: {
    #A: {
      let empty#1 = {}
      field: (null|{
        n: int
      })
      field: (〈0;let empty#1〉 & {
        n: 3
      })
    }
    out: 〈import;list〉.Concat([
      [
        〈2;#A〉,
      ],
    ])
  }
  eliminated: {
    #empty: {}
    x: (null|{
      n: 3
    })
    x: (〈0;#empty〉 & {
      n: 3
    })
    out: len(〈0;x〉)
  }
  simplified: {
    #struct: {
      field: ({
        n: 3
      } & 〈0;g〉)
      g: {}
    }
    out: (〈0;#struct〉 & {})
  }
}
