Skip to content

adding an alias to a top-level field seems to change its scope #4312

@mvdan

Description

@mvdan
cd ${WORK}/without_alias
exec cue export .

cd ${WORK}/with_alias
exec cue export .

cd ${WORK}/with_aliasv2
exec cue export .

-- without_alias/one.cue --
package p

foo: "foo value"
one_field: foo
-- without_alias/two.cue --
package p

two_field: foo
-- with_alias/one.cue --
package p

A=foo: "foo value"

one_alias: A
one_field: foo
-- with_alias/two.cue --
package p

two_field: foo
-- with_aliasv2/one.cue --
@experiment(aliasv2)

package p

foo~A: "foo value"

one_alias: A
one_field: foo
-- with_aliasv2/two.cue --
@experiment(aliasv2)

package p

two_field: foo

As of 256bd97:

> cd ${WORK}/without_alias
$WORK/without_alias
> exec cue export .
[stdout]
{
    "foo": "foo value",
    "one_field": "foo value",
    "two_field": "foo value"
}
> cd ${WORK}/with_alias
$WORK/with_alias
> exec cue export .
[stderr]
two_field: reference "foo" not found:
    ./two.cue:3:12
[exit status 1]
FAIL: f.txtar:5: unexpected command failure
> cd ${WORK}/with_aliasv2
$WORK/with_aliasv2
> exec cue export .
[stdout]
{
    "foo": "foo value",
    "one_alias": "foo value",
    "one_field": "foo value",
    "two_field": "foo value"
}

This is very odd. Surely, adding an alias to a field declaration should not suddenly change the scope of a field.

Confusingly, this is broken with the current aliases, but works fine with aliasv2. I wonder if this is by accident.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions