Skip to content

Commit 2dec682

Browse files
authored
AppliedTypes returned by baseType shouldn't have type lambdas as constructors (#17071)
AppliedTypes returned by baseType shouldn't have type lambdas as constructors In tests/pos/argDenot-alpakka.min.scala, we want `(([O] =>> Foo[O, S]) @UV)[Int]`.baseType(`Foo`) to return `Foo[Int]` rather than an applied type lambda, so that we can rely on the invariant that the type arguments of the type returned by baseType(cls) correspond to the type parameter of cls which `NamedType#argDenot` is implicitly relying on. This could be achieved by removing the initial if branch from the AppliedType case in baseTypeOf, since the recursive fallback will always work, but it makes sense to keep a special case for performance, so we just explicitly add as a condition to the fast-path that the type constructor of the AppliedType can't be a lambda.
2 parents 6e5be23 + 9afa629 commit 2dec682

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,13 +2226,12 @@ object SymDenotations {
22262226
def computeApplied = {
22272227
btrCache(tp) = NoPrefix
22282228
val baseTp =
2229-
if (tycon.typeSymbol eq symbol) tp
2230-
else (tycon.typeParams: @unchecked) match {
2229+
if (tycon.typeSymbol eq symbol) && !tycon.isLambdaSub then tp
2230+
else (tycon.typeParams: @unchecked) match
22312231
case LambdaParam(_, _) :: _ =>
22322232
recur(tp.superType)
22332233
case tparams: List[Symbol @unchecked] =>
22342234
recur(tycon).substApprox(tparams, args)
2235-
}
22362235
record(tp, baseTp)
22372236
baseTp
22382237
}

tests/pos/argDenot-alpakka.min.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.annotation.unchecked.uncheckedVariance as uV
2+
3+
trait Test:
4+
def test[S] =
5+
val a: (([O] =>> Foo[O, S]) @uV)[Int] = ???
6+
a.m()
7+
8+
class Foo[X, Y]:
9+
def m(): Y = ???

tests/pos/argDenot-alpakka.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.annotation.unchecked.uncheckedVariance as uV
2+
3+
trait Test:
4+
def split[I, M](in: Flow[I, Byte, M]): SubFlow[Byte, M, in.Repr]
5+
def test =
6+
split(new Flow[Int, Byte, Unit])
7+
.via[Char]
8+
.merge
9+
.filter()
10+
11+
trait FlowOps[+Out, +Mat]:
12+
type Repr[+O] <: FlowOps[O, Mat] { type Repr[+O] = FlowOps.this.Repr[O] }
13+
def via[O]: Repr[O] = ???
14+
def filter(): Repr[Out] = ???
15+
16+
class Flow[-In, +Out, +Mat] extends FlowOps[Out, Mat]:
17+
type Repr[+O] = Flow[In @uV, O, Mat @uV]
18+
19+
class SubFlow[+Out, +Mat, +F[+_]] extends FlowOps[Out, Mat]:
20+
type Repr[+O] = SubFlow[O, Mat @uV, F @uV]
21+
def merge: F[Out] = ???

0 commit comments

Comments
 (0)