Skip to content
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

Backport "Restore pre-3.3.2 behavior of inline implicit def" to LTS #20975

Merged
merged 1 commit into from
Jul 3, 2024
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
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]]