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

Treat single splats with same restriction as equivalent #12584

Conversation

HertzDevil
Copy link
Contributor

Fixes #12579 by ensuring the old behavior of Crystal::Def#min_max_args_sizes is used during overload ordering. (The new one is still used in other places like error reporting.)

Has no effect on -Dpreview_overload_order.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic kind:regression Something that used to correctly work but no longer works labels Oct 9, 2022
Comment on lines +361 to +372
def old_min_args_size
if splat_index = self.def.splat_index
args = self.def.args
unless args[splat_index].name.empty?
default_value_index = args.index(&.default_value)
min_size = default_value_index || args.size
min_size -= 1 unless default_value_index.try(&.< splat_index)
return min_size
end
end
self.min_size
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation looks very similar to Def#min_max_args_sizes. Could we just use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First the max size is unaffected, second we already know that -Dpreview_overload_order is not in effect at this point. If we check for that flag in min_max_args_sizes itself there could be a performance impact and some other uses of the method also become inconsistent (e.g. too-few-argunents errors).

There might be a better way to derive the old min size from the new min size. I don't know if it would end up doing the same amount of work though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with leaving it like that. But maybe add a comment about this to the code?

@straight-shoota straight-shoota added this to the 1.6.1 milestone Oct 10, 2022
@straight-shoota straight-shoota merged commit 809c49e into crystal-lang:master Oct 11, 2022
@beta-ziliani beta-ziliani self-assigned this Oct 11, 2022
@HertzDevil HertzDevil deleted the bug/splat-restriction-redefinition branch October 15, 2022 21:12
lbguilherme pushed a commit to lbguilherme/crystal that referenced this pull request Oct 24, 2022
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. kind:regression Something that used to correctly work but no longer works topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression on redefining a method with splat parameter (overload ordering)
3 participants