Skip to content

Commit 234e59c

Browse files
committed
Fix #9509: Reveal further arguments in extension method applications
They were hidden in an IgnroedProto before for fear that we might need an implicit conversion. But none is possible at this point.
1 parent bb23fea commit 234e59c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,13 @@ 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+
// (1) always reveal further arguments in extension method applications,
2090+
// (2) but do not reveal anything else in a prototype.
2091+
// (1) is needed for i9509.scala (2) is needed for i6900.scala
2092+
val normPt = pt match
2093+
case IgnoredProto(ignored: FunProto) => ignored
2094+
case _ => pt
2095+
20892096
/** Integrate the type arguments from `currentPt` into `methodRef`, and produce
20902097
* a matching expected type.
20912098
* If `currentPt` is ignored, the new expected type will be ignored too.
@@ -2097,9 +2104,9 @@ trait Applications extends Compatibility {
20972104
val core = untpd.TypeApply(methodRef, targs.map(untpd.TypedSplice(_)))
20982105
(core, if (wasIgnored) IgnoredProto(restpe) else restpe)
20992106
case _ =>
2100-
(methodRef, pt)
2107+
(methodRef, normPt)
21012108
}
2102-
val (core, pt1) = integrateTypeArgs(pt)
2109+
val (core, pt1) = integrateTypeArgs(normPt)
21032110
val app = withMode(Mode.SynthesizeExtMethodReceiver) {
21042111
typed(untpd.Apply(core, untpd.TypedSplice(receiver) :: Nil), pt1, ctx.typerState.ownedVars)
21052112
}

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(head: A, tail: AList[A])
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)