Skip to content

Commit 3d70dd2

Browse files
authored
Merge pull request #9542 from dotty-staging/fix-#9509
Fix #9509: Reveal further arguments in extension method applications
2 parents 7d14d44 + 826ffb3 commit 3d70dd2

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,20 +2086,23 @@ trait Applications extends Compatibility {
20862086
* where <type-args> comes from `pt` if it is a (possibly ignored) PolyProto.
20872087
*/
20882088
def extMethodApply(methodRef: untpd.Tree, receiver: Tree, pt: Type)(using Context): Tree = {
2089-
/** Integrate the type arguments from `currentPt` into `methodRef`, and produce
2090-
* a matching expected type.
2091-
* If `currentPt` is ignored, the new expected type will be ignored too.
2089+
/** Integrate the type arguments (if any) from `currentPt` into `tree`, and produce
2090+
* an expected type that hides the appropriate amount of information through IgnoreProto.
20922091
*/
2093-
def integrateTypeArgs(currentPt: Type, wasIgnored: Boolean = false): (untpd.Tree, Type) = currentPt match {
2094-
case IgnoredProto(ignored) =>
2095-
integrateTypeArgs(ignored, wasIgnored = true)
2092+
def normalizePt(tree: untpd.Tree, currentPt: Type): (untpd.Tree, Type) = currentPt match
2093+
// Always reveal expected arguments to guide inference (needed for i9509.scala)
2094+
case IgnoredProto(ignored: FunOrPolyProto) =>
2095+
normalizePt(tree, ignored)
2096+
// Always hide expected member to allow for chained extensions (needed for i6900.scala)
2097+
case _: SelectionProto =>
2098+
(tree, IgnoredProto(currentPt))
20962099
case PolyProto(targs, restpe) =>
2097-
val core = untpd.TypeApply(methodRef, targs.map(untpd.TypedSplice(_)))
2098-
(core, if (wasIgnored) IgnoredProto(restpe) else restpe)
2100+
val tree1 = untpd.TypeApply(tree, targs.map(untpd.TypedSplice(_)))
2101+
normalizePt(tree1, restpe)
20992102
case _ =>
2100-
(methodRef, pt)
2101-
}
2102-
val (core, pt1) = integrateTypeArgs(pt)
2103+
(tree, currentPt)
2104+
2105+
val (core, pt1) = normalizePt(methodRef, pt)
21032106
val app = withMode(Mode.SynthesizeExtMethodReceiver) {
21042107
typed(untpd.Apply(core, untpd.TypedSplice(receiver) :: Nil), pt1, ctx.typerState.ownedVars)
21052108
}

tests/pos/i9509.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum AList[+A] {
2+
case Cons[X](head: X, tail: AList[X]) extends AList[X]
3+
case Nil
4+
}
5+
6+
object AList {
7+
extension [A](l: AList[A]) def sum(using numeric: Numeric[A]): A = l match {
8+
case Cons(x, xs) => numeric.plus(x, xs.sum(using numeric))
9+
case Nil => numeric.zero
10+
}
11+
}

0 commit comments

Comments
 (0)