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.