Skip to content

Commit 9cbc48b

Browse files
authored
Fix i14451 (#16010)
Fixes #14451 Implicitly assumed type clauses could only be at the beginning, which is wrong since: ```scala extension (x: Int) def foo[T](y: T) = ??? ``` de-sugars to something like: ```scala def foo(x: Int)[T](y: T) = ??? ``` To fix it, I implement `stripInferrable`, a variant of `stripImplicit` which also drops type clauses, and use it in `resultIsMethod` I suspect the other uses of `stripImplicit` could be simplified, or even fixed (assuming they make the same mistake as `resultIsMethod`), by using `stripInferrable`
2 parents 684ae79 + c87e56b commit 9cbc48b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,17 @@ trait Applications extends Compatibility {
14731473
}
14741474
}
14751475

1476-
/** Drop any implicit parameter section */
1476+
/** Drop any leading type or implicit parameter sections */
1477+
def stripInferrable(tp: Type)(using Context): Type = tp match {
1478+
case mt: MethodType if mt.isImplicitMethod =>
1479+
stripInferrable(resultTypeApprox(mt))
1480+
case pt: PolyType =>
1481+
stripInferrable(pt.resType)
1482+
case _ =>
1483+
tp
1484+
}
1485+
1486+
/** Drop any leading implicit parameter sections */
14771487
def stripImplicit(tp: Type)(using Context): Type = tp match {
14781488
case mt: MethodType if mt.isImplicitMethod =>
14791489
stripImplicit(resultTypeApprox(mt))
@@ -2042,7 +2052,7 @@ trait Applications extends Compatibility {
20422052
skip(alt.widen)
20432053

20442054
def resultIsMethod(tp: Type): Boolean = tp.widen.stripPoly match
2045-
case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType]
2055+
case tp: MethodType => stripInferrable(tp.resultType).isInstanceOf[MethodType]
20462056
case _ => false
20472057

20482058
record("resolveOverloaded.narrowedApplicable", candidates.length)

tests/pos/i14451.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
class Foo
3+
4+
extension (dfVal: Foo)
5+
def f0(step: Int): Foo = ???
6+
def f0: Foo = ???
7+
val v0 = (new Foo).f0
8+
9+
extension (dfVal: Foo)
10+
def f1[T](step: Int): Foo = ???
11+
def f1: Foo = ???
12+
val v1 = (new Foo).f1
13+
14+
extension (dfVal: Foo)
15+
def f2[T](step: Int): Foo = ???
16+
def f2[T]: Foo = ???
17+
val v2 = (new Foo).f2
18+
19+
extension [A](dfVal: Foo)
20+
def f3[T](step: Int): Foo = ???
21+
def f3: Foo = ???
22+
val v3 = (new Foo).f3
23+
24+
extension [A](dfVal: Foo)
25+
def f4[T](step: Int): Foo = ???
26+
def f4[T]: Foo = ???
27+
val v4 = (new Foo).f4

0 commit comments

Comments
 (0)