Skip to content

Commit a7bae7a

Browse files
committed
Allow eta-expansion of inline defs
The fact that this wasn't allowed before seems to be a bug and not an intentional restriction: the check was originally introduced in a019a4e for "typelevel methods" which are only vaguely related to today's inline methods.
1 parent 94eb6b7 commit a7bae7a

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

-2
Original file line numberDiff line numberDiff line change
@@ -3976,12 +3976,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39763976

39773977
// Reasons NOT to eta expand:
39783978
// - we reference a constructor
3979-
// - we reference a typelevel method
39803979
// - we are in a pattern
39813980
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
39823981
if arity >= 0
39833982
&& !tree.symbol.isConstructor
3984-
&& !tree.symbol.isAllOf(InlineMethod)
39853983
&& !ctx.mode.is(Mode.Pattern)
39863984
&& !(isSyntheticApply(tree) && !functionExpected)
39873985
then

Diff for: tests/neg/i12207.scala

+1-1
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

Diff for: tests/neg/i7459.scala

+1-1
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.*

Diff for: tests/pos/inline-eta.scala

+9
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)