Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A when branch matching on multiple record patterns using field punning within tags causes duplicate name error #7167

Open
isaacvando opened this issue Oct 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@isaacvando
Copy link
Collaborator

# This works as expected
func1 = \val ->
    when val is
        A x | B x -> x
        C -> {}

# This works as expected
func2 = \val ->
    when val is
        A { x } | B x -> x
        C -> {}

# This works as expected
func3 = \val ->
    when val is
        A { x: x } | B { x: x } -> x
        C -> {}

# This causes a duplicate name error
func4 = \val ->
    when val is
        A { x } | B { x } -> x
        C -> {}
── DUPLICATE NAME in Model.roc ─────────────────────────────────────────────────

The x name is first defined here:

151│          A { x } | B { x } -> x
                ^^^^^

But then it's defined a second time here:

151│          A { x } | B { x } -> x
                          ^^^^^

Since these variables have the same name, it's easy to use the wrong
one by accident. Give one of them a new name.


── NAME NOT BOUND IN ALL PATTERNS in Model.roc ─────────────────────────────────

x is not bound in all patterns of this when branch

151│          A { x } | B { x } -> x
                  ^

Identifiers introduced in a when branch must be bound in all patterns
of the branch. Otherwise, the program would crash when it tries to use
an identifier that wasn't bound!

────────────────────────────────────────────────────────────────────────────────

2 errors and 0 warnings found in 15 ms
@isaacvando isaacvando added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant