Skip to content

Commit 0d79122

Browse files
committed
used derived types to type arguments of dependent function type
1 parent ab1ab3c commit 0d79122

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1463,14 +1463,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
14631463
if isErasedClass then arg.withAddedFlags(Erased) else arg
14641464
}
14651465
return typedDependent(newParams)
1466-
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
1467-
val typeArgs = appDef.termParamss.head.map(_.tpt) :+ resTpt
14681466
val core =
14691467
if mt.hasErasedParams then TypeTree(defn.PolyFunctionClass.typeRef)
14701468
else
1469+
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
1470+
val paramTpts = appDef.termParamss.head.map(p => TypeTree(p.tpt.tpe).withSpan(p.tpt.span))
14711471
val funSym = defn.FunctionSymbol(numArgs, isContextual, isImpure)
14721472
val tycon = TypeTree(funSym.typeRef)
1473-
AppliedTypeTree(tycon, typeArgs)
1473+
AppliedTypeTree(tycon, paramTpts :+ resTpt)
14741474
RefinedTypeTree(core, List(appDef), ctx.owner.asClass)
14751475
end typedDependent
14761476

tests/run/i19629/Test_2.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
class Container[Y1, G[_]]:
3+
lazy val outer: Knit[CP, G] = new:
4+
type Res = Y1
5+
def visit[R](caseInFst: [F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[G, [x] =>> CP[F1[x], Y]]) => R): R =
6+
caseInFst[G, Res](outer)(new TypeEqK[G, [x] =>> CP[G[x], Res]] {})
7+
8+
@main def Test =
9+
val knit = new Container[Unit, Option].outer
10+
val res = knit.visit:
11+
[F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[Option, [x] =>> CP[F1[x], Y]]) => 42
12+
assert(res == 42)

tests/run/i19629/lib_1.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait CP[A,B]
2+
trait TypeEqK[F[_], G[_]]
3+
4+
trait Knit[CP[_, _], F[_]] {
5+
type Res
6+
7+
def visit[R](
8+
caseInFst: [F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[F, [x] =>> CP[F1[x], Y]]) => R
9+
): R
10+
}

0 commit comments

Comments
 (0)