Skip to content

Commit f87d4cb

Browse files
bishaboshaWojciechMazur
authored andcommitted
used derived types to type arguments of dependent function type
[Cherry-picked 0d79122]
1 parent 4a64a17 commit f87d4cb

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
@@ -1439,14 +1439,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
14391439
if isErasedClass then arg.withAddedFlags(Erased) else arg
14401440
}
14411441
return typedDependent(newParams)
1442-
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
1443-
val typeArgs = appDef.termParamss.head.map(_.tpt) :+ resTpt
14441442
val core =
14451443
if mt.hasErasedParams then TypeTree(defn.ErasedFunctionClass.typeRef)
14461444
else
1445+
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
1446+
val paramTpts = appDef.termParamss.head.map(p => TypeTree(p.tpt.tpe).withSpan(p.tpt.span))
14471447
val funSym = defn.FunctionSymbol(numArgs, isContextual, isImpure)
14481448
val tycon = TypeTree(funSym.typeRef)
1449-
AppliedTypeTree(tycon, typeArgs)
1449+
AppliedTypeTree(tycon, paramTpts :+ resTpt)
14501450
RefinedTypeTree(core, List(appDef), ctx.owner.asClass)
14511451
end typedDependent
14521452

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)