-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Issue 2532 - '=' does not give a boolean result #122
Conversation
Change the error message.
|
The shorter the error message, the better. I'm not sure what's wrong with the original message? I have tons of these errors when porting C code and it's never a problem for me to figure out what went wrong. But YMMV. |
|
I think the main purpose of this error message is to warn against people that don't realise there's a == operator for equality testing. Seasoned developers will spot this without problem, but the newbies should be told to use == instead of =. |
|
The problem with the original error message is that it complains boolean assignments do not give boolean results. While it does give a very useful warning for the common bug of using = when meaning to use ==, the message does not accurately describe what the error is. The actual rule the compiler uses is that an assignment expression cannot be used in a condition (if, ||, &&, ?: etc) that expects a boolean. I think 'if(auto x = 5)' is technically declaration and initialization, not assignment, so the proposed error message is still accurate. |
|
Yes, in fact, it doesn't even matter if it's not accurate -- the current situation is that the error message is not true regarding the compiled expression; my comment is about the accuracy of the error message regarding a different expression. So even if technically not true (which is debatable), within the context, your initial change is good enough to identify the problem with the compiled code. So I think it's fine. |
Improve std.conv.to (3)
Issue 2532 - '=' does not give a boolean result
|
An even better message: |
Love it. |
|
Me too. Including a suggestion on the most likely way to fix it should be thought about for all the error messages. Like the spell checker on undefined identifiers, this can make things much quicker to understand and fix for the users. I've noticed even git has a spell checker. Try typing in: git posh and you'll see what I mean! |
|
btw, clang went one step further and introduced special fixit hints for obvious cases: http://clang.llvm.org/diagnostics.html |
Changed to a better error message.
http://d.puremagic.com/issues/show_bug.cgi?id=2532