Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

literalExpressionEvaluator binary operations with booleans #838

Closed
piwonskp opened this issue Jan 15, 2023 · 2 comments · Fixed by #871
Closed

literalExpressionEvaluator binary operations with booleans #838

piwonskp opened this issue Jan 15, 2023 · 2 comments · Fixed by #871
Assignees
Labels
good first issue Good for newcomers

Comments

@piwonskp
Copy link
Contributor

In the literalExpressionEvaluator pass, a binary expression could be calculated at compile time, even when only one argument is a literal. In the case of a boolean literal with the && operator, the following is done:

case '&&': // false && x = false
	return notNullMember ? null : false;

It is also known that if notNullMember is true, the result of the operation is the other member, and so the binaryOperation expression can be replaced by the left or right expression correspondingly. This is something that could be added.

Same thing happens for || operator

Add tests for this behaviour

@piwonskp piwonskp converted this from a draft issue Jan 15, 2023
@piwonskp piwonskp added the good first issue Good for newcomers label Jan 15, 2023
@aniket2405
Copy link
Contributor

aniket2405 commented Jan 18, 2023

"It is also known that if notNullMember is true, the result of the operation is the other member, and so the binaryOperation expression can be replaced by the left or right expression correspondingly."

In this case, we are considering the situation when one of the expression is a null. Then, if the notNullMember is true, should the function not return null itself, and not the other member? Similar case for the || operator.

@cicr99
Copy link
Contributor

cicr99 commented Jan 18, 2023

No, if an expression returns null that doesn't mean its value is null, it means it wasn't possible to determine its value at compilation time. Check evaluateLiteralExpression function for better understanding

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants