internal/core/eval: fix irregular dynamic fields

Fixes #560 which was caused by an escaping bug
for the closedness check of dynamic fields.

Change-Id: I25adc0135cc7b3e744bce4ec15f7072369146494
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7461
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/testdata/comprehensions/fields.txtar b/cue/testdata/comprehensions/fields.txtar
new file mode 100644
index 0000000..8cf3a10
--- /dev/null
+++ b/cue/testdata/comprehensions/fields.txtar
@@ -0,0 +1,57 @@
+Issue #560
+
+-- cue.mod/module.cue --
+module: "example.com"
+
+-- in.cue --
+import "strings"
+
+#User: {
+    tags_str: string
+    tags_map: {
+         for k, v in strings.Split(tags_str, " ") {
+             "\(v)": string
+         }
+         "{a}": string
+    }
+}
+
+user: {
+    #User
+    tags_str: "b {c}"
+}
+-- out/eval --
+(struct){
+  #User: (#struct){
+    tags_str: (string){ string }
+    tags_map: (_|_){
+      // [incomplete] error in call to strings.Split: non-concrete value string
+      "{a}": (string){ string }
+    }
+  }
+  user: (#struct){
+    tags_str: (string){ "b {c}" }
+    tags_map: (#struct){
+      "{a}": (string){ string }
+      b: (string){ string }
+      "{c}": (string){ string }
+    }
+  }
+}
+-- out/compile --
+--- in.cue
+{
+  #User: {
+    tags_str: string
+    tags_map: {
+      for k, v in 〈import;strings〉.Split(〈1;tags_str〉, " ") {
+        "\(〈1;v〉)": string
+      }
+      "{a}": string
+    }
+  }
+  user: {
+    〈1;#User〉
+    tags_str: "b {c}"
+  }
+}
diff --git a/internal/core/eval/optionals.go b/internal/core/eval/optionals.go
index 947dd19..7edabca 100644
--- a/internal/core/eval/optionals.go
+++ b/internal/core/eval/optionals.go
@@ -235,7 +235,8 @@
 	if !ok {
 		return false
 	}
-	return f.SelectorString(c) == s.Str
+	label := f.StringValue(c)
+	return label == s.Str
 }
 
 type patternMatcher adt.Conjunct