Bug 21765 – Assignment-as-condition error with checkaction=context
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-03-25T02:19:34Z
Last change time
2021-03-25T05:50:49Z
Keywords
pull
Assigned to
No Owner
Creator
moonlightsentinel
Comments
Comment #0 by moonlightsentinel — 2021-03-25T02:19:34Z
-------------------------------
ref int boo();
void main()
{
assert(( boo() = 2) == 2);
}
-------------------------------
Only with -checkaction=context:
checkaction.d(5): Error: assignment cannot be used as a condition, perhaps `==` was meant?
Comment #1 by dlang-bot — 2021-03-25T02:57:59Z
@MoonlightSentinel created dlang/dmd pull request #12307 "Fix 21765 - Assignment-as-condition error with checkaction=context" fixing this issue:
- Fix 21765 - Assignment-as-condition error with checkaction=context
Don't eagerly check `toBoolean` if `op` is nested in another expression.
This still catches `assert((a = 1))` but prevents invalid errors for
assignments in `assert((a = 1) == 1)`.
https://github.com/dlang/dmd/pull/12307
Comment #2 by dlang-bot — 2021-03-25T05:50:49Z
dlang/dmd pull request #12307 "Fix 21765 - Assignment-as-condition error with checkaction=context" was merged into master:
- 9cb19e23cf092ced72c1a56f479027abdb6748d5 by MoonlightSentinel:
Fix 21765 - Assignment-as-condition error with checkaction=context
Don't eagerly check `toBoolean` if `op` is nested in another expression.
This still catches `assert((a = 1))` but prevents invalid errors for
assignments in `assert((a = 1) == 1)`.
https://github.com/dlang/dmd/pull/12307