cue/ast/astutil: detect aliasv2 postfix label-name redeclarations
In the postfix dual form `"foo"~(K, V):`, the K identifier captures
the label name, and the resolver inserts it into the surrounding
struct scope with the label expression (e.g. a *ast.BasicLit) as the
entry's node. The uniqueness check inspected only that node type,
which falls outside the let-like set (*ast.LetClause, *ast.Alias,
*ast.Field, …), so two sibling fields could declare the same K alias
and the second silently overwrote the first instead of producing an
error like the equivalent old-style `N=("foo"):` form does.
Thread the entry's link through isLet and mustBeUnique, and treat any
entry linked to an *ast.PostfixAlias as let-like and required to be
unique. The other postfix-alias insertion sites (single-form ~X and
dual-form V) already pass *ast.Field as the node, so they were already
handled; pattern constraints `[…]~(K, V):` insert into a field-local
scope where uniqueness is automatic.
Fixes #4342.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Id8604dfdb3e1c82b526cdf1ce88b3650bbf9ab60
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1236313
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>