Skip to content

Commit fbd55a4

Browse files
committed
Fix isInlineable check to work during overloading resolution
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.
1 parent fe6d690 commit fbd55a4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ object Inlines:
4949

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

5460
/** Should call be inlined in this context? */
5561
def needsInlining(tree: Tree)(using Context): Boolean = tree match {

tests/pos/i21410c.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AppliedPIso[A, B]()
2+
case class User(age: Int)
3+
4+
object Test:
5+
extension [From, To](from: From)
6+
def focus(): AppliedPIso[From, From] = ???
7+
transparent inline def focus(inline lambda: (From => To)): Any = ???
8+
9+
10+
val u = User(1)
11+
val ap: AppliedPIso[User, User] = u.focus(_.age) // error

0 commit comments

Comments
 (0)