Skip to content

Conversation

@RblSb
Copy link
Member

@RblSb RblSb commented Jun 1, 2025

There is also some idea to skip warning when you wrap condition in additional parentheses in first commit.
Related to #8634

var foo = false;
var foo2 = false;
// warning for these cases
var value = (foo = foo2) ? true : false;
if (foo = true) {}
if (foo = null) {}
if ({123; foo = true;}) {}

while (foo = true) {}
do {} while (foo = true);

var dyn:Dynamic = false;
if (dyn = null) {}
if (dyn = false) {}

if ((foo = null) && (foo = true)) {}
if ((foo = null) && ((foo = true) && (foo = true))) {}

// no warning
if ({foo = true; true;}) {}

@kLabz
Copy link
Contributor

kLabz commented Jun 1, 2025

That double parenthesis syntax seems out of place :/

@skial skial mentioned this pull request Jun 2, 2025
1 task
@RblSb RblSb force-pushed the warn-condition-assign branch from 30ab76c to d215498 Compare November 21, 2025 06:02
@RblSb
Copy link
Member Author

RblSb commented Nov 21, 2025

I will write test if you guys think that this is good warning / implementation to have

@kLabz
Copy link
Contributor

kLabz commented Nov 21, 2025

For the Dynamic (ie is_bool is false) case, I think it makes sense.

The bool case is more problematic. Assignment of a variable of type T being itself of type T is by design, so writing if (a = true) { ... } is totally valid.

Maybe add a sub warning for the bool case, that would be off by default?

`bool = null`, `dyn = dyn2` are reported

`bool = false`, `bool = bool2` is opt in
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.

2 participants