-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5386: Normalize unary operator expressions #5479
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
Conversation
A unary operator expression `pre.op` where `op` is one of `+`, `-`, `~`, `!` that has a constant type `ConstantType(v)` but that is not a constant expression (i.e. `pre` has side-effects) is translated to { pre; v } This avoids the situation where we have a Select node which does not have a symbol.
Derived from biboudis:fix-#5386. Note: Always do PRs from staging then others can work on them. |
if (isIdempotentExpr(tree1)) Literal(value) | ||
else tree1 match { | ||
case Select(qual, _) if tree1.tpe.isInstanceOf[ConstantType] => | ||
// it's a unary operator; Simplify `pre.op` to `{ pre; v }` where `v` is the value of `pre.op` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we lose op before pickling, then it'll be missing from the IDE in go-to-definition/find-all-references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't really get what's special about unary operators here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do not get a symbol. So nothing is lost when doing the transform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why do they not get a symbol ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because constant folding replaces the type with a ConstantType.
Add test showing that user-defined unary operators do not cause a problem, even if they have constant types.
A unary operator expression
pre.op
whereop
is one of+
,-
,~
,!
that has a constant type
ConstantType(v)
but that is not a constant expression(i.e.
pre
has side-effects) is translated toThis avoids the situation where we have a Select node which does not have a symbol.