Skip to content

Allow eta-expansion of inline defs #18249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3976,12 +3976,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

// Reasons NOT to eta expand:
// - we reference a constructor
// - we reference a typelevel method
// - we are in a pattern
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
if arity >= 0
&& !tree.symbol.isConstructor
&& !tree.symbol.isAllOf(InlineMethod)
&& !ctx.mode.is(Mode.Pattern)
&& !(isSyntheticApply(tree) && !functionExpected)
then
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i12207.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ extension [T](t: T) inline def pi[P <: Tuple](using P): T = ???
inline def env[P <: Tuple, T](op: P ?=> T): P ?=> T = op

@main def Test =
env { pi[String] } // error // error
env { pi[String] } // error
2 changes: 1 addition & 1 deletion tests/neg/i7459.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ object Foo {
inline def summon[T](x: T): T = x match {
case t: T => t
}
println(summon) // error
println(summon)
}

import scala.deriving.*
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/inline-eta.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo(x: Int)

object A:
inline def bar(x: Int): Int = x
val g1 = bar
val g2: Int => Int = bar

def foo(xs: List[Int]) =
xs.map(Foo.apply) // use the `inline def apply` constructor proxy