Skip to content

Commit

Permalink
Do now bind inline parameters when lifting args
Browse files Browse the repository at this point in the history
Fixes #13411
  • Loading branch information
nicolasstucki committed Aug 31, 2021
1 parent f8dec07 commit 5ac9f20
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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, _))
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i13411.scala
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions tests/pos/i13411b/Constants.java
Original file line number Diff line number Diff line change
@@ -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;
}
32 changes: 32 additions & 0 deletions tests/pos/i13411b/Test.scala
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5ac9f20

Please sign in to comment.