this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/ast/astutil: fix false positive in label expression check for let clauses

The label expression check in pattern constraints walks up through
scopes to detect circular references. For field values, the inField
flag acts as a barrier to stop the walk. But for let clause values,
inField was never set, so the walk could escape beyond the let
clause's value into outer scopes and falsely flag identifiers there.

Set inField when walking let clause expressions, mirroring the
behavior for field values.

Fixes #4202

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I65152772657feaa36bac7aad269947d40367399a
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1231219
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

+26 -1
+21 -1
cmd/cue/cmd/testdata/script/eval_e.txtar
··· 19 19 # when a for comprehension's if-guard references the same definition 20 20 # used in a pattern constraint on the iterated struct. 21 21 exec cue eval -e _out issue4202/x.cue 22 - stdout '_\|_' 22 + cmp stdout expect/issue4202/stdout 23 23 24 24 -- expect/nonExist/stdout -- 25 25 -- expect/nonExist/stderr -- ··· 81 81 for k, v in x 82 82 if k =~ #K {v}, 83 83 ] 84 + -- expect/issue4202/stdout -- 85 + 86 + [ 87 + for k, v in X 88 + if k =~ K.#x { 89 + v 90 + }] 91 + 92 + //cue:path: x 93 + let X = { 94 + { 95 + [K.#x]: _ 96 + } 97 + a: 1 98 + } 99 + 100 + //cue:path: #K 101 + let K = { 102 + #x: string 103 + }
+5
cue/ast/astutil/resolve.go
··· 471 471 saved := s.index[name] 472 472 delete(s.index, name) // The same name may still appear in another scope 473 473 474 + // Set inField so that the label expression check in pattern constraints 475 + // does not walk beyond the let clause's value. A let clause's value is 476 + // a separate context, just like a field value. 477 + s.inField = true 474 478 ast.Walk(x.Expr, s.Before, nil) 479 + s.inField = false 475 480 s.index[name] = saved 476 481 return false 477 482