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

Error on tuple size with multi assign #11695

Open
straight-shoota opened this issue Jan 4, 2022 · 2 comments
Open

Error on tuple size with multi assign #11695

straight-shoota opened this issue Jan 4, 2022 · 2 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@straight-shoota
Copy link
Member

straight-shoota commented Jan 4, 2022

#11145 introduced a new compiler error when the target size in 1-to-n assignments don't match up.

That triggers when the assigned tuples has more elements than the number of targets:

a, b = {1, 2, 3} # Error: cannot assign Tuple(Int32, Int32, Int32) to 2 targets

When the assigned tuple has less elements than the number of targets, a similar error would be expected. But you get a different one:

a, b, c = {1, 2} # Error: index out of bounds for Tuple(Int32, Int32) (2 not in -2..1)

The expected error as per the introducing PR would be this:

a, b, c = {1, 2} # Error: cannot assign Tuple(Int32, Int32) to 3 targets

The reason is that the error specific to multi assign mismatch is triggered in CleanupTransformer, but before the compiler gets there, the expanded code already triggers the index error for accessing an out of range tuple element.

I'm not sure why this wasn't done properly. Maybe it was too complex? The initial PR already has a spec for this, but it's marked as pending.

This isn't a big issue. The important part is that there's a compiler error, it could just be more specific.

/cc @HertzDevil

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Jan 4, 2022
@asterite
Copy link
Member

asterite commented Jan 4, 2022

@straight-shoota Could you clarify what's the expected behavior here? Both errors look fine to me.

@straight-shoota
Copy link
Member Author

The expected error as per the introducing PR would be this:

a, b, c = {1, 2} # Error: cannot assign Tuple(Int32, Int32) to 3 targets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

No branches or pull requests

2 participants