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

Issue 2532 - '=' does not give a boolean result #122

Merged
merged 1 commit into from
Nov 8, 2011

Conversation

yebblies
Copy link
Member

Changed to a better error message.

http://d.puremagic.com/issues/show_bug.cgi?id=2532

@ghost
Copy link

ghost commented Jun 13, 2011

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.

@Poita
Copy link
Contributor

Poita commented Jun 13, 2011

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 =.

@yebblies
Copy link
Member Author

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.

@schveiguy
Copy link
Member

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.

braddr pushed a commit to braddr/dmd that referenced this pull request Sep 15, 2011
WalterBright added a commit that referenced this pull request Nov 8, 2011
Issue 2532 - '=' does not give a boolean result
@WalterBright WalterBright merged commit 6279cb9 into dlang:master Nov 8, 2011
@WalterBright
Copy link
Member

An even better message:

772ff9a

@yebblies
Copy link
Member Author

yebblies commented Nov 8, 2011

An even better message:

Love it.

@WalterBright
Copy link
Member

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!

@Trass3r
Copy link
Contributor

Trass3r commented Nov 8, 2011

btw, clang went one step further and introduced special fixit hints for obvious cases: http://clang.llvm.org/diagnostics.html
A corresponding rewriter class can use those to automatically replace every mistake with the proposed fix if desired (something which can also be perfectly used for code-breaking changes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants