Skip to content

Commit

Permalink
Fix beta-reduction with Nothing and null args (scala#16938)
Browse files Browse the repository at this point in the history
Use parameter type as binding type when the argument is of type
`Nothing` or `null`.

Fixes part of scala#15165
  • Loading branch information
nicolasstucki authored Feb 21, 2023
2 parents 0b54a0b + f5bc2a0 commit 1821107
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/BetaReduce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
else if arg.tpe.dealias.isInstanceOf[ConstantType] then arg.tpe.dealias
else arg.tpe.widen
val binding = ValDef(newSymbol(ctx.owner, param.name, flags, tpe, coord = arg.span), arg).withSpan(arg.span)
if !(tpe.isInstanceOf[ConstantType] && isPureExpr(arg)) then
bindings += binding
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i15165.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def test1 = { (y: Int) => y + 1 }.apply(???)

class C:
def x: Int = 8

def test2 = { (c: C) => c.x }.apply(null)

0 comments on commit 1821107

Please sign in to comment.