It turns out the semantics of the spec is somewhat awkward,
though theoretically nicer. It seems like we do need to change
the definition somewhat to make it less awkward, or at least
come up with a good workaround before adopting the spec.

We have introduce a small hack to mimic the old behavior for scalar
values.

Note that the value of p below is now 2 (default), but should
be the non-concrete 2 | int.

Proof:
    p: *((*1 | int) & 2)  | int   // substitution of both P conjuncts in p
    p: *(*_|_ | 2)  | int         // U1: distribute conjuncts
    p: *_|_ | 2  | int            // M2: remove mark
    p: 2  | int                   // value after removing default.
-- in.cue --
Q: *1 | int    @test(eq, *1 | int)
q: *Q | int    @test(eq, *1 | int) // 1 as expected

P: *1 | int
P: 2
p: *P | int    @test(eq, *2 | int) // now 2, but should be (2 | int), according to the spec:

// Here the inner default may not be used as it is masked by the outer default.
r: (*3 | (*1 | 2)) & (1 | 2)   @test(eq, 1 | 2)

// Here the inner default is used, as there are no defaults marked in the
// outer disjunction.
s: (3 | (*1 | 2)) & (1 | 2)    @test(eq, *1 | 2)

s1: #Size & {min: 5}            @test(eq, {
	min: 5
	max: *5 | >5
	res: *0 | >=0 & int
})

#Size: {
	max: >min | *min
	res: uint | *0
	min: >res | *(1 + res)
	@test(eq, {
		max: *1 | >0 | >1
		res: *0 | >=0 & int
		min: *1 | >0
	})
}

staged: {
	c: ("a" | "b") & (*(*"a" | string) | string)
	d: (*(*"a" | string) | string) & ("a" | "b")
	@test(eq, {c: *"a" | *"b", d: *"a" | "b"})
}

issue763a: {
	#A: {
		v: "a" | "b" | "c" // change to string to fix
	}

	h: [string]: #A

	h: [=~"^b"]: #A & {
		v: *h.a.v | string
	}

	h: a: {
		v: *"a" | string
	}

	h: baa: _
	h: boo: _
	@test(eq, {
		#A: {v: "a" | "b" | "c"}
		h: {
			a: {v: *"a" | "b" | "c"}
			baa: {v: *"a" | "b" | "c"}
			boo: {v: *"a" | "b" | "c"}
		}
	})
}
-- out/todo.txt --
staged.c: evalv3 gives *"a" | *"b" (two defaults), while evalv2 gives *"a" | "b".
This is a known semantic difference in default handling; see diff/explanation in the
original golden-file version. TODO(defaults): consider with a potential default redesign.
-- out/eval/stats --
Leaks:  19
Freed:  130
Reused: 103
Allocs: 46
Retain: 0

Unifications: 28
Conjuncts:    184
Disjuncts:    121

NumCloseIDs: 10
