Bug 12390 – [REG2.066a] "has no effect in expression" diagnostic regression

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-17T04:25:00Z
Last change time
2014-04-07T17:14:51Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2014-03-17T04:25:39Z
///////// test.d //////// struct S { int i; } S fun() { return S(42); } void main() { fun().i == 4; } ///////////////////////// DMD 2.065: test.d(7): Error: == has no effect in expression (fun().i == 4) DMD master compiles. Introduced in https://github.com/D-Programming-Language/dmd/pull/3186
Comment #1 by k.hara.pg — 2014-03-29T00:06:37Z
This is not a regression. Rather the behavior change was an actual fix of rejects-valid bug. (In reply to comment #0) > DMD 2.065: > test.d(7): Error: == has no effect in expression (fun().i == 4) 'fun' is not pure, so essentially its call could have side effect. So the error message was incorrect in 2.065 and earlier. > DMD master compiles. Therefore, current git-head behavior is correct.
Comment #2 by dlang-bugzilla — 2014-03-29T02:30:04Z
Even if fun is not pure, the code performs two redundant operations (obtaining a field of the result, then comparing it to something). fun(); This should compile. fun().i == 4; This should not. > Rather the behavior change was an actual fix of rejects-valid bug. In a [Refactoring] pull request?
Comment #3 by dlang-bugzilla — 2014-03-29T02:40:27Z
I should note that the error WAS working as intended - this was a bug in my code, I intended to write "fun().i = 4" (the function returned by ref in my code), but did not catch the bug until I spotted it accidentally. So this is definitely a regression which affects real use cases.
Comment #4 by k.hara.pg — 2014-04-07T00:50:09Z
OK, I confirmed the issue. It's a bug in the value discarding check. And, this is 2.066 git-head only regression. https://github.com/D-Programming-Language/dmd/pull/3432
Comment #5 by github-bugzilla — 2014-04-07T10:39:53Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/89ca0a14eb2b0a3e232a2eded5f43693d02510e3 fix Issue 12390 - "has no effect in expression" diagnostic regression When value discarding check on statements, the side-effect check should not be done deeply. https://github.com/D-Programming-Language/dmd/commit/b80a6da17ac42c8976f5e552faff1b969593bdc0 Merge pull request #3432 from 9rnsr/fix12390 [REG2.066a] Issue 12390 - "has no effect in expression" diagnostic regression