internal/core/eval: fix empty data vertex bug

Recognize when an empty Vertex is used as data
(e.g. after a Merge) it is not recognized as a struct.

Change-Id: I769f123cb0e3403cb520f928b188a78f8a9b28b5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7084
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/cmd/cue/cmd/testdata/script/merge_interaction.txt b/cmd/cue/cmd/testdata/script/merge_interaction.txt
new file mode 100644
index 0000000..b602e70
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/merge_interaction.txt
@@ -0,0 +1,30 @@
+cue cmd dump
+
+cmp stdout expect-stdout
+
+-- combine.cue --
+package kube
+
+map: [string]: spec: {}
+map: bartender: {}
+
+-- combine_tool.cue --
+package kube
+
+import (
+	"encoding/yaml"
+	"tool/cli"
+)
+
+objects: [ for x in map {x}]
+
+command: dump: {
+	cli.Print & {
+		text: yaml.MarshalStream(objects)
+	}
+}
+-- cue.mod --
+
+-- expect-stdout --
+spec: {}
+
diff --git a/internal/core/eval/eval.go b/internal/core/eval/eval.go
index 4b81ce0..de558e4 100644
--- a/internal/core/eval/eval.go
+++ b/internal/core/eval/eval.go
@@ -1135,17 +1135,20 @@
 	ctx := n.ctx
 
 	if x, ok := v.(*adt.Vertex); ok {
-		if m, ok := x.Value.(*adt.StructMarker); ok && m.NeedClose {
-			ci := closedInfo(n.node)
-			ci.isClosed = true // TODO: remove
-			id = ci.InsertDefinition(id, x)
-			ci.Canopy[id].IsClosed = true
-			ci.Canopy[id].IsDef = false
+		if m, ok := x.Value.(*adt.StructMarker); ok {
+			n.aStruct = x
+			if m.NeedClose {
+				ci := closedInfo(n.node)
+				ci.isClosed = true // TODO: remove
+				id = ci.InsertDefinition(id, x)
+				ci.Canopy[id].IsClosed = true
+				ci.Canopy[id].IsDef = false
+			}
 		}
 
-		if !x.IsData() && len(x.Conjuncts) > 0 {
-			cyclic := env != nil && env.Cyclic
+		cyclic := env != nil && env.Cyclic
 
+		if !x.IsData() && len(x.Conjuncts) > 0 {
 			if isComplexStruct(x) {
 				closedInfo(n.node).InsertSubtree(id, n, x, cyclic)
 				return
@@ -1167,13 +1170,9 @@
 
 		case *adt.StructMarker:
 			for _, a := range x.Arcs {
-				if a.Label.IsString() {
-					n.aStruct = x
-				}
-				// TODO, insert here as
-				n.insertField(a.Label, adt.MakeConjunct(nil, a, id))
-				// sub, _ := n.node.GetArc(a.Label)
-				// sub.Add(a)
+				c := adt.MakeConjunct(nil, a, id)
+				c = updateCyclic(c, cyclic, nil)
+				n.insertField(a.Label, c)
 			}
 
 		default: