cue: enable recursive opening when embedding

Change-Id: Ibcdf364c6d9e70af8bc444b54931c974d5441c10
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3041
Reviewed-by: roger peppe <rogpeppe@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/binop.go b/cue/binop.go
index 0395753..7a54bdb 100644
--- a/cue/binop.go
+++ b/cue/binop.go
@@ -699,9 +699,7 @@
 					return ctx.mkErr(src, "field %q declared as definition and regular field",
 						ctx.labelStr(a.feature))
 				}
-				// TODO: using opUnify here disables recursive opening in
-				// embedding. Change to op enable it.
-				v = mkBin(ctx, src.Pos(), opUnify, b.v, v)
+				v = mkBin(ctx, src.Pos(), op, b.v, v)
 				obj.arcs[i].v = v
 				obj.arcs[i].cache = nil
 				obj.arcs[i].optional = a.optional && b.optional
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index 98e505f..4a42ca2 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -1235,10 +1235,10 @@
 		`,
 		out: `<0>{` +
 			`E :: <1>C{a: <2>C{b: int}}, ` +
-			`S :: <3>C{a: _|_((<4>C{b: int} & <5>C{c: int}):field "b" not allowed in closed struct), b: 3}, ` +
-			`e1 :: _|_((<6>.S & <7>C{a: <8>C{c: 4}}):field "b" not allowed in closed struct), ` +
-			`v1: <9>C{a: _|_((<10>C{b: int} & <11>C{c: int}):field "b" not allowed in closed struct), b: 3}, ` +
-			`e2: <12>C{a: _|_((<13>C{b: int} & <14>C{c: int}):field "b" not allowed in closed struct), b: 3}}`,
+			`S :: <3>C{a: <4>C{b: int, c: int}, b: 3}, ` +
+			`e1 :: _|_((<5>.S & <6>C{a: <7>C{c: 4}}):field "b" not allowed in closed struct), ` +
+			`v1: <8>C{a: <9>C{b: int, c: 4}, b: 3}, ` +
+			`e2: <10>C{a: _|_(4:field "d" not allowed in closed struct), b: 3}}`,
 	}, {
 		desc: "closing structs",
 		in: `
diff --git a/doc/ref/spec.md b/doc/ref/spec.md
index a6c394d..aab56f8 100644
--- a/doc/ref/spec.md
+++ b/doc/ref/spec.md
@@ -1281,17 +1281,7 @@
 A struct may contain an _embedded value_, an operand used
 as a declaration, which must evaluate to a struct.
 An embedded value of type struct is unified with the struct in which it is
-embedded, but disregarding the restrictions imposed by closed structs
-for its top-level fields.
-<!--TODO: consider relaxing it to the below.
-An embedded value of type struct is unified with the struct in which it is
 embedded, but disregarding the restrictions imposed by closed structs.
-
-Note that in the above definition we cannot say that the fields of the
-embedded struct are added: references within these fields referring to
-the embedded struct should be rewired to reference the new struct.
-This would not be the case with  per-field definition.
--->
 A struct resulting from such a unification is closed if either of the involved
 structs were closed.