-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix beta-reduction with Nothing
and null
args
#16938
Conversation
Fixes part of scala#15165
It fixes this sub-issue #15165 (comment) |
Why do we not always just use the parameter types? |
Using the argument type propagates call site knowledge into the implementation of the lambda. This can be used in |
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.
Looks good! I tried playing with it for a bit, seems solid
@@ -128,7 +128,10 @@ object BetaReduce: | |||
ref.symbol | |||
case _ => | |||
val flags = Synthetic | (param.symbol.flags & Erased) | |||
val tpe = if arg.tpe.dealias.isInstanceOf[ConstantType] then arg.tpe.dealias else arg.tpe.widen | |||
val tpe = | |||
if arg.tpe.isBottomType then param.tpe.widenTermRefExpr |
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.
I'm not sure why we use widenTermRefExpr
here (and not widen
for example), just curious.
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.
To keep the type precise. For example, if we have a singleton String
type we do not want to widen it to String
. For example ((x: "foo") => x: "foo").apply(???)
should become val x: "foo" = ???; x: "foo"
and not val x: String = ???; x: "foo"
. The second one would not type check after beta-reduction.
Use parameter type as binding type when the argument is of type
Nothing
ornull
.Fixes part of #15165