From 880350d830b62de21ab68f779c2932814add9897 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 31 Aug 2021 14:49:53 +0200 Subject: [PATCH] Do not bind inline parameters when lifting args Fixes #13411 --- .../dotty/tools/dotc/typer/EtaExpansion.scala | 6 ++-- tests/pos/i13411.scala | 12 +++++++ tests/pos/i13411b/Constants.java | 5 +++ tests/pos/i13411b/Test.scala | 32 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i13411.scala create mode 100644 tests/pos/i13411b/Constants.java create mode 100644 tests/pos/i13411b/Test.scala diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index 32849de6f560..74891fccd985 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -88,8 +88,10 @@ abstract class Lifter { methRef.widen match { case mt: MethodType => args.lazyZip(mt.paramNames).lazyZip(mt.paramInfos).map { (arg, name, tp) => - val lifter = if (tp.isInstanceOf[ExprType]) exprLifter else this - lifter.liftArg(defs, arg, if (name.firstPart contains '$') EmptyTermName else name) + if tp.hasAnnotation(defn.InlineParamAnnot) then arg + else + val lifter = if (tp.isInstanceOf[ExprType]) exprLifter else this + lifter.liftArg(defs, arg, if (name.firstPart contains '$') EmptyTermName else name) } case _ => args.mapConserve(liftArg(defs, _)) diff --git a/tests/pos/i13411.scala b/tests/pos/i13411.scala new file mode 100644 index 000000000000..d310cdbdad21 --- /dev/null +++ b/tests/pos/i13411.scala @@ -0,0 +1,12 @@ +class Foo +class Bar extends Foo + +inline def thingy(a: Int = 0, b: Int = 0, inline c: Foo = new Bar) = { + inline c match { + case _: Bar => + } +} + +def x = 1 + +def test = thingy(b = x) diff --git a/tests/pos/i13411b/Constants.java b/tests/pos/i13411b/Constants.java new file mode 100644 index 000000000000..0cb5fb31ac5e --- /dev/null +++ b/tests/pos/i13411b/Constants.java @@ -0,0 +1,5 @@ +public class Constants { + public static final int A = 0; + public static final int B = 2; + public static final int C = 3; +} diff --git a/tests/pos/i13411b/Test.scala b/tests/pos/i13411b/Test.scala new file mode 100644 index 000000000000..4ed586485d86 --- /dev/null +++ b/tests/pos/i13411b/Test.scala @@ -0,0 +1,32 @@ +class broken { + sealed trait Foo + case object A extends Foo + case object B extends Foo + case object C extends Foo + case object D extends Foo + + inline def foo(inline f: Foo) = inline f match { + case _: A.type => "the letter a" + case _: B.type => "the letter b" + case _: C.type => "the letter c" + case _: D.type => "the letter d" + } + + inline def thingy( + depthClampEnable: Boolean = false, + rasterizerDiscardEnable: Boolean = false, + polygonMode: Int = 0, + cullMode: Int = 0, + frontFace: Int = 0, + depthBiasEnable: Boolean = false, + depthBiasConstantFactor: Float = 0, + depthBiasClamp: Float = 0, + depthBiasSlopeFactor: Float = 0, + lineWidth: Float = 0, + inline f: Foo = A, + ) = { + foo(f) + } + + thingy(polygonMode = Constants.A, cullMode = Constants.B, frontFace = Constants.C, lineWidth = 1.0f) +}