Skip to content

Commit 0125b46

Browse files
Merge pull request #13429 from dotty-staging/i13411
Do not bind inline parameters when lifting args
2 parents a3743da + 880350d commit 0125b46

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ abstract class Lifter {
8888
methRef.widen match {
8989
case mt: MethodType =>
9090
args.lazyZip(mt.paramNames).lazyZip(mt.paramInfos).map { (arg, name, tp) =>
91-
val lifter = if (tp.isInstanceOf[ExprType]) exprLifter else this
92-
lifter.liftArg(defs, arg, if (name.firstPart contains '$') EmptyTermName else name)
91+
if tp.hasAnnotation(defn.InlineParamAnnot) then arg
92+
else
93+
val lifter = if (tp.isInstanceOf[ExprType]) exprLifter else this
94+
lifter.liftArg(defs, arg, if (name.firstPart contains '$') EmptyTermName else name)
9395
}
9496
case _ =>
9597
args.mapConserve(liftArg(defs, _))

tests/pos/i13411.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo
2+
class Bar extends Foo
3+
4+
inline def thingy(a: Int = 0, b: Int = 0, inline c: Foo = new Bar) = {
5+
inline c match {
6+
case _: Bar =>
7+
}
8+
}
9+
10+
def x = 1
11+
12+
def test = thingy(b = x)

tests/pos/i13411b/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Constants {
2+
public static final int A = 0;
3+
public static final int B = 2;
4+
public static final int C = 3;
5+
}

tests/pos/i13411b/Test.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class broken {
2+
sealed trait Foo
3+
case object A extends Foo
4+
case object B extends Foo
5+
case object C extends Foo
6+
case object D extends Foo
7+
8+
inline def foo(inline f: Foo) = inline f match {
9+
case _: A.type => "the letter a"
10+
case _: B.type => "the letter b"
11+
case _: C.type => "the letter c"
12+
case _: D.type => "the letter d"
13+
}
14+
15+
inline def thingy(
16+
depthClampEnable: Boolean = false,
17+
rasterizerDiscardEnable: Boolean = false,
18+
polygonMode: Int = 0,
19+
cullMode: Int = 0,
20+
frontFace: Int = 0,
21+
depthBiasEnable: Boolean = false,
22+
depthBiasConstantFactor: Float = 0,
23+
depthBiasClamp: Float = 0,
24+
depthBiasSlopeFactor: Float = 0,
25+
lineWidth: Float = 0,
26+
inline f: Foo = A,
27+
) = {
28+
foo(f)
29+
}
30+
31+
thingy(polygonMode = Constants.A, cullMode = Constants.B, frontFace = Constants.C, lineWidth = 1.0f)
32+
}

0 commit comments

Comments
 (0)