From ec9117a16436a07944ba0b7832c861e7c9977205 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Tue, 3 Dec 2024 13:18:56 +0100 Subject: [PATCH] cue/parser: always allow predeclared identifiers on RHS CUE reserves identifiers starting with __ for builtin functionality. A bug in the parser currently disallows them to be used by themselves on the RHS of a field. Signed-off-by: Marcel van Lohuizen Change-Id: I5c71a8931ea19104735a43211580fbe6e09f8b6a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205229 Reviewed-by: Matthew Sackman Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- cue/parser/parser.go | 2 +- cue/parser/parser_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cue/parser/parser.go b/cue/parser/parser.go index 4341546c278..cc039cf954a 100644 --- a/cue/parser/parser.go +++ b/cue/parser/parser.go @@ -1007,7 +1007,7 @@ func (p *parser) parseLabel(rhs bool) (label ast.Label, expr ast.Expr, decl ast. } case *ast.Ident: - if strings.HasPrefix(x.Name, "__") { + if strings.HasPrefix(x.Name, "__") && !rhs { p.errf(x.NamePos, "identifiers starting with '__' are reserved") } diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go index da55ea7380d..8c6053716db 100644 --- a/cue/parser/parser_test.go +++ b/cue/parser/parser_test.go @@ -260,6 +260,11 @@ func TestParse(t *testing.T) { [X=_]: X `, "a: {b: {c: d}}, c: a, d: a.b, e: a.b.c, \"f\": f, [X=_]: X", + }, { + "predeclared identifiers", + `a: __string + __int: 2`, + "a: __string, __int: 2\nidentifiers starting with '__' are reserved", }, { "empty fields", `