D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21765 - Assignment-as-condition error with checkaction=context
Summary: Assignment-as-condition error with checkaction=context
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-03-25 02:19 UTC by moonlightsentinel
Modified: 2021-03-25 05:50 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2021-03-25 02:19:34 UTC
-------------------------------
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 Dlang Bot 2021-03-25 02:57:59 UTC
@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 Dlang Bot 2021-03-25 05:50:49 UTC
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