Skip to content

Commit fd89fc8

Browse files
authored
Backport "Allow eta-expansion of inline defs" to LTS (#19124)
Backports #18249 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 58e0f7e + 690a6aa commit fd89fc8

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,12 +3902,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39023902

39033903
// Reasons NOT to eta expand:
39043904
// - we reference a constructor
3905-
// - we reference a typelevel method
39063905
// - we are in a pattern
39073906
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
39083907
if arity >= 0
39093908
&& !tree.symbol.isConstructor
3910-
&& !tree.symbol.isAllOf(InlineMethod)
39113909
&& !ctx.mode.is(Mode.Pattern)
39123910
&& !(isSyntheticApply(tree) && !functionExpected)
39133911
then

tests/neg/i12207.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ extension [T](t: T) inline def pi[P <: Tuple](using P): T = ???
55
inline def env[P <: Tuple, T](op: P ?=> T): P ?=> T = op
66

77
@main def Test =
8-
env { pi[String] } // error // error
8+
env { pi[String] } // error

tests/neg/i7459.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object Foo {
22
inline def summon[T](x: T): T = x match {
33
case t: T => t
44
}
5-
println(summon) // error
5+
println(summon)
66
}
77

88
import scala.deriving.*

tests/pos/inline-eta.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo(x: Int)
2+
3+
object A:
4+
inline def bar(x: Int): Int = x
5+
val g1 = bar
6+
val g2: Int => Int = bar
7+
8+
def foo(xs: List[Int]) =
9+
xs.map(Foo.apply) // use the `inline def apply` constructor proxy

0 commit comments

Comments
 (0)