Skip to content

Commit

Permalink
Backport "Restore pre-3.3.2 behavior of inline implicit def" to LTS (
Browse files Browse the repository at this point in the history
…#20975)

Backports #19877 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 3, 2024
2 parents ebbb9e2 + bfcdef8 commit f32fa2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ object Flags {
val LazyGiven: FlagSet = Given | Lazy
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
val InlineMethod: FlagSet = Inline | Method
val InlineImplicitMethod: FlagSet = Implicit | InlineMethod
val InlineParam: FlagSet = Inline | Param
val InlineByNameProxy: FlagSet = InlineProxy | Method
val JavaEnumTrait: FlagSet = JavaDefined | Enum // A Java enum trait
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3939,10 +3939,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

// Reasons NOT to eta expand:
// - we reference a constructor
// - we reference an inline implicit def (see #19862)
// - 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(InlineImplicitMethod)
&& !ctx.mode.is(Mode.Pattern)
&& !(isSyntheticApply(tree) && !functionExpected)
then
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i19862.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.language.implicitConversions

object Test:
implicit inline def uhOh[A](value: A): A =
compiletime.error("Should not have been called")
def test =
// Compiles because `uhOh` fails to eta-expand and we fallback to `Predef.$conforms[A, A]`
summon[Function1[Int, Int]]

0 comments on commit f32fa2b

Please sign in to comment.