Skip to content

Commit f32fa2b

Browse files
Backport "Restore pre-3.3.2 behavior of inline implicit def" to LTS (#20975)
Backports #19877 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents ebbb9e2 + bfcdef8 commit f32fa2b

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ object Flags {
581581
val LazyGiven: FlagSet = Given | Lazy
582582
val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */
583583
val InlineMethod: FlagSet = Inline | Method
584+
val InlineImplicitMethod: FlagSet = Implicit | InlineMethod
584585
val InlineParam: FlagSet = Inline | Param
585586
val InlineByNameProxy: FlagSet = InlineProxy | Method
586587
val JavaEnumTrait: FlagSet = JavaDefined | Enum // A Java enum trait

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

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

39403940
// Reasons NOT to eta expand:
39413941
// - we reference a constructor
3942+
// - we reference an inline implicit def (see #19862)
39423943
// - we are in a pattern
39433944
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
39443945
if arity >= 0
39453946
&& !tree.symbol.isConstructor
3947+
&& !tree.symbol.isAllOf(InlineImplicitMethod)
39463948
&& !ctx.mode.is(Mode.Pattern)
39473949
&& !(isSyntheticApply(tree) && !functionExpected)
39483950
then

tests/pos/i19862.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.language.implicitConversions
2+
3+
object Test:
4+
implicit inline def uhOh[A](value: A): A =
5+
compiletime.error("Should not have been called")
6+
def test =
7+
// Compiles because `uhOh` fails to eta-expand and we fallback to `Predef.$conforms[A, A]`
8+
summon[Function1[Int, Int]]

0 commit comments

Comments
 (0)