internal/core/eval: ... does not apply to defintions

Change-Id: Ic4ba09d7876ef5763c20b33708758190e5daf401
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7201
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/testdata/definitions/issue539.txtar b/cue/testdata/definitions/issue539.txtar
new file mode 100644
index 0000000..a62afdf
--- /dev/null
+++ b/cue/testdata/definitions/issue539.txtar
@@ -0,0 +1,45 @@
+-- in.cue --
+#Schema: {
+	...
+}
+
+Component: {
+	hostname: string | *"localhost"
+
+	#foo: {
+		hello: "world"
+	}
+}
+
+hello: #Schema & Component
+-- out/eval --
+(struct){
+  #Schema: (#struct){
+  }
+  Component: (struct){
+    hostname: (string){ |(*(string){ "localhost" }, (string){ string }) }
+    #foo: (#struct){
+      hello: (string){ "world" }
+    }
+  }
+  hello: (#struct){
+    hostname: (string){ |(*(string){ "localhost" }, (string){ string }) }
+    #foo: (#struct){
+      hello: (string){ "world" }
+    }
+  }
+}
+-- out/compile --
+--- in.cue
+{
+  #Schema: {
+    ...
+  }
+  Component: {
+    hostname: (string|*"localhost")
+    #foo: {
+      hello: "world"
+    }
+  }
+  hello: (〈0;#Schema〉 & 〈0;Component〉)
+}
diff --git a/internal/core/eval/closed.go b/internal/core/eval/closed.go
index a33c324..ea96a32 100644
--- a/internal/core/eval/closed.go
+++ b/internal/core/eval/closed.go
@@ -483,8 +483,8 @@
 	if o == nil {
 		return false, false
 	}
-	for ; o != nil; o = o.next {
-		if len(o.additional) > 0 || o.isOpen {
+	for isRegular := f.IsRegular(); o != nil; o = o.next {
+		if isRegular && (len(o.additional) > 0 || o.isOpen) {
 			return true, false
 		}
 
@@ -494,6 +494,10 @@
 			}
 		}
 
+		if !isRegular {
+			continue
+		}
+
 		for _, b := range o.bulk {
 			if b.check.Match(ctx, f) {
 				return true, false