Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Warn when ternary operator results are not read only #243

Merged
merged 1 commit into from Oct 10, 2021

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Oct 10, 2021

Closes #241

For guard ? expr_true : expr_false, first guard is evaluated, then stored as guard, and it's opposite stored as !guard. Then some magic happens for the result, it's translated as !guard * expr_false + guard * expr_true, meaning both expressions are evaluated in any case.

Warn if any of the expression is not read only is a small improvement but won't prevent side effects.

The ideal solution would be to convert the ternary into a full action 2 in this case, but it's really not trivial to implement.

@glx22 glx22 merged commit 68e8092 into OpenTTD:master Oct 10, 2021
@glx22 glx22 deleted the ternary branch October 10, 2021 17:46
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.

Attempt to warn when use of ternary op might fail due to side effects
2 participants