fix: allow calling trait impl method from struct if multiple impls exist#7074
Closed
fix: allow calling trait impl method from struct if multiple impls exist#7074
Conversation
Contributor
Compilation Memory Report
|
Contributor
Execution Memory Report
|
Collaborator
Author
|
Closing as this PR is only part of the fix but doing the full fix is very hard. |
Member
|
@asterite can you make a new PR with tests from this one with |
This was referenced Jan 16, 2025
jfecher
reviewed
Jan 16, 2025
Comment on lines
-1521
to
-1525
| // Only remove the existing function from scope if it is from a trait impl as | ||
| // well. If it is from a non-trait impl that should override trait impl methods | ||
| // anyway so that Foo::bar always resolves to the non-trait impl version. | ||
| if self.interner.function_meta(&existing).trait_impl.is_some() { | ||
| module.remove_function(method.name_ident()); |
Contributor
There was a problem hiding this comment.
IIRC without this check the compiler would still call one of the trait methods on error that wasn't removed instead of erroring that there were two matching candidates or something. Could be wrong, this has been here a while
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Related to #7090
Summary
Edit: this one is very had to fix. The main issue is that:
U60Repr::from2()U60Repr::from2FuncId. In this case it's a trait method so there are potentially multipleFuncId, so we'd need to represent the result in a different way here. And once we do that, change the code to support this new result variant.It seems we had logic in place to remove a method definition if it gives an error while adding it. When multiple trait impl methods existed for the same struct (in different impls), the second definition would erase both, though only from the
ModuleData(I think the definitions still exist somewhere else so that's why usingTrait::worked).I'm not sure why that was done, but I changed it to not do that. All tests seem to pass, so either that was unneeded or there is a scenario that breaks with this change but it's untested.
Additional Context
I also introduced refactors/renames to make the code a bit clearer.
Documentation
Check one:
PR Checklist
cargo fmton default settings.