Skip to content

Commit af69895

Browse files
committed
Restore pre-3.3.2 behavior of inline implicit def
`inline implicit def` is not really a supported feature since it combines Scala 3's `inline` with Scala 2's `implicit` where the latter should eventually be deprecated. This however didn't prevent at least one project from using this combination in a way that was broken by #18249, see #19862 for the details. The issue is that when definining: implicit def foo(x: A): B = ... Then `foo` is a valid implicit search candidate when looking up an implicit `Function1[A, B]`. However, before #18249 if instead we wrote: inline implicit def foo(x: A): B = ... Then `foo` would be considered as an implicit search candidate but discarded because eta-expansion was disabled. There is no particular reason for `inline implicit def` to behave differently from `implicit def` here, but since `implicit def` is a legacy feature and since Scala 3.3 is an LTS release, we choose to restore the pre-#18249 behavior for compatibility reasons. Fixes #19862.
1 parent b02d898 commit af69895

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

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

+1
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 JavaEnum: FlagSet = JavaDefined | Enum // A Java enum trait

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

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

39943994
// Reasons NOT to eta expand:
39953995
// - we reference a constructor
3996+
// - we reference an inline implicit def (see #19862)
39963997
// - we are in a pattern
39973998
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
39983999
if arity >= 0
39994000
&& !tree.symbol.isConstructor
4001+
&& !tree.symbol.isAllOf(InlineImplicitMethod)
40004002
&& !ctx.mode.is(Mode.Pattern)
40014003
&& !(isSyntheticApply(tree) && !functionExpected)
40024004
then

tests/pos/i19862.scala

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