Skip to content

Commit 8c54c42

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 8c54c42

File tree

2 files changed

+9
-2
lines changed

2 files changed

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