Skip to content

Commit

Permalink
Fix isInlineable check to work during overloading resolution
Browse files Browse the repository at this point in the history
Overloading may create temporary symbols via `Applications#resolveMapped`, these
symbols do not carry the annotations from the original symbols which means the
`isInlineable` would always return false for them. This matters because during
the course of overloading resolution we might call
`ProtoTypes.Compatibility#constrainResult` which special-cases transparent
inline methods.

Fixes a regression in Monocle introduced in the previous commit.
  • Loading branch information
smarter committed Oct 10, 2024
1 parent 7f1b82b commit eafa761
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ object Inlines:

/** Can a call to method `meth` be inlined? */
def isInlineable(meth: Symbol)(using Context): Boolean =
meth.is(Inline) && meth.hasAnnotation(defn.BodyAnnot) && !inInlineMethod
meth.is(Inline)
&& (meth.hasAnnotation(defn.BodyAnnot)
// Ensure `isInlineable` works with temporary symbols created during
// overloading resolution by `Applications#resolveMapped`.
// Testcase: tests/pos/i21410c.scala
|| meth.hasAnnotation(defn.MappedAlternativeAnnot))
&& !inInlineMethod

/** Should call be inlined in this context? */
def needsInlining(tree: Tree)(using Context): Boolean = tree match {
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i21410c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AppliedPIso[A, B]()
case class User(age: Int)

object Test:
extension [From, To](from: From)
def focus(): AppliedPIso[From, From] = ???
transparent inline def focus(inline lambda: (From => To)): Any = ???


val u = User(1)
val ap: AppliedPIso[User, User] = u.focus(_.age) // error

0 comments on commit eafa761

Please sign in to comment.