From f5bc2a00b0d4dae90b5ac433d88313767e0e65c5 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 16 Feb 2023 16:32:07 +0100 Subject: [PATCH] Fix beta-reduction with `Nothing` and `null` args Fixes part of #15165 --- compiler/src/dotty/tools/dotc/transform/BetaReduce.scala | 5 ++++- tests/pos/i15165.scala | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i15165.scala diff --git a/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala b/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala index 97dc4697db6d..c586bb06cc29 100644 --- a/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala +++ b/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala @@ -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 diff --git a/tests/pos/i15165.scala b/tests/pos/i15165.scala new file mode 100644 index 000000000000..15e89c90e900 --- /dev/null +++ b/tests/pos/i15165.scala @@ -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)