cue/parser: fix parsing bug

Closes #276

Change-Id: I80149e8bbc0acf680eb7c2528a09b48340bb0dc0
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5002
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/ast.go b/cue/ast.go
index 17996da..269c379 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -450,6 +450,10 @@
 				return v.errf(lab, "invalid field name: %v", lab)
 			}
 			val := v.walk(n.Value)
+			if val == nil {
+				return v.errf(lab, "invalid field value: %v",
+					internal.DebugStr(n.Value))
+			}
 			v.object.insertValue(v.ctx(), f, opt, isDef, val, attrs, v.doc)
 			v.doc = leftOverDoc
 
diff --git a/cue/ast_test.go b/cue/ast_test.go
index 0aed17f..bc8acd1 100644
--- a/cue/ast_test.go
+++ b/cue/ast_test.go
@@ -393,6 +393,12 @@
 		env_:: foo: "bar"
 			`,
 		out: "env_.*: alias not allowed in list:\n    test:3:20\n<0>{}",
+	}, {
+		// Issue #276
+		in: `
+			a:     int=<100
+			`,
+		out: "alias \"int\" not allowed as value:\n    test:2:11\n<0>{}",
 	}}
 	for _, tc := range testCases {
 		t.Run("", func(t *testing.T) {
diff --git a/cue/parser/parser.go b/cue/parser/parser.go
index 177513d..f1adb42 100644
--- a/cue/parser/parser.go
+++ b/cue/parser/parser.go
@@ -883,6 +883,9 @@
 			if expr == nil {
 				expr = p.parseRHS()
 			}
+			if a, ok := expr.(*ast.Alias); ok {
+				p.errf(expr.Pos(), "alias %q not allowed as value", debugStr(a.Ident))
+			}
 			m.Value = expr
 			break
 		}
diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go
index 1082dbc..46f4a03 100644
--- a/cue/parser/parser_test.go
+++ b/cue/parser/parser_test.go
@@ -489,6 +489,12 @@
 		}
 		`,
 		out: "package name, @t1(v1), {@t2(v2)}, a: {a: 1, @t3(v3), @t4(v4), c: 2}",
+	}, {
+		desc: "Issue #276",
+		in: `
+		a: int=>2
+		`,
+		out: "a: int=>2\nalias \"int\" not allowed as value",
 	}}
 	for _, tc := range testCases {
 		t.Run(tc.desc, func(t *testing.T) {