Skip to content

Commit

Permalink
cue/parser: always allow predeclared identifiers on RHS
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: I5c71a8931ea19104735a43211580fbe6e09f8b6a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205229
Reviewed-by: Matthew Sackman <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Dec 7, 2024
1 parent 46c1cb2 commit ec9117a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cue/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
5 changes: 5 additions & 0 deletions cue/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
`
Expand Down

0 comments on commit ec9117a

Please sign in to comment.