-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Match if expression is const, to get the proper error message #16086
Conversation
|
Thanks for your pull request and interest in making D better, @ryuukk! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16086" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will need to update test cases
|
Please add "Fix bugzilla issue 19114" and "Fix bugzilla issue 24353" to the commit message so the bot links the issues. |
|
Is the fix correct at least? |
| @@ -1719,7 +1719,14 @@ private FuncDeclaration findBestOpApplyMatch(Expression ethis, FuncDeclaration f | |||
| if (f.isThis()) | |||
| { | |||
| if (!MODimplicitConv(mod, tf.mod)) | |||
| { | |||
| if (mod & MODFlags.const_) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findBestOpApplyMatch iterates through all of the overloads of opApply and selects the best match (if there is one) or errors in case you have more than one match. In case there is no match, the function returns null. This patch modifies the code so that if the instance type does not match the opApply instance type and the instance type is const then the considered opApply is chosen as the best match. This is wrong for multiple reasons:
- you are simply making
consta particular case here; what happens withimmutable,shared, etc.? - you are considering a function that is not a match to be a match; this might break other parts of the compiler that call this function.
- this is not going to work properly when you have multiple opApply's that fail for similar reasons; you are just going to pick the last failing as the best match.
- consider the case when having both a const and a mutable opApply; you will obtain a wrong ambiguity error.
I think that the only solution here is to:
- call
findBestOpApplyMatch. - if there is a single opApply defined and it's not a match, then try calling it anyway (
resolveFuncCall) to obtain a proper error message. - if you have multiple opApplys and none of them are a match, then the current error message is fine.
So, the fix is not in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct fix.
|
@ryuukk are you willing to implement the proper solution? |
|
Not right now, I have too much to do on my current project |
|
When you want to continue, please re-open / open a new PR. |
Consider:
Before:
After:
Fixes bugzilla Issue 19114 - cannot uniquely infer foreach argument types is not a descriptive message
Fixes bugzilla Issue 24353 - Misleading error for foreach when opApply has wrong qualifier