Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "used derived types to type arguments of dependent function type" to LTS #20970

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
used derived types to type arguments of dependent function type
[Cherry-picked 0d79122]
bishabosha authored and WojciechMazur committed Jul 2, 2024
commit f87d4cb13d9064af31d24342e2483c3e989b33d3
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
@@ -1439,14 +1439,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if isErasedClass then arg.withAddedFlags(Erased) else arg
}
return typedDependent(newParams)
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
val typeArgs = appDef.termParamss.head.map(_.tpt) :+ resTpt
val core =
if mt.hasErasedParams then TypeTree(defn.ErasedFunctionClass.typeRef)
else
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
val paramTpts = appDef.termParamss.head.map(p => TypeTree(p.tpt.tpe).withSpan(p.tpt.span))
val funSym = defn.FunctionSymbol(numArgs, isContextual, isImpure)
val tycon = TypeTree(funSym.typeRef)
AppliedTypeTree(tycon, typeArgs)
AppliedTypeTree(tycon, paramTpts :+ resTpt)
RefinedTypeTree(core, List(appDef), ctx.owner.asClass)
end typedDependent

12 changes: 12 additions & 0 deletions tests/run/i19629/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

class Container[Y1, G[_]]:
lazy val outer: Knit[CP, G] = new:
type Res = Y1
def visit[R](caseInFst: [F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[G, [x] =>> CP[F1[x], Y]]) => R): R =
caseInFst[G, Res](outer)(new TypeEqK[G, [x] =>> CP[G[x], Res]] {})

@main def Test =
val knit = new Container[Unit, Option].outer
val res = knit.visit:
[F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[Option, [x] =>> CP[F1[x], Y]]) => 42
assert(res == 42)
10 changes: 10 additions & 0 deletions tests/run/i19629/lib_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
trait CP[A,B]
trait TypeEqK[F[_], G[_]]

trait Knit[CP[_, _], F[_]] {
type Res

def visit[R](
caseInFst: [F1[_], Y] => (k: Knit[CP, F1]) => (ev: TypeEqK[F, [x] =>> CP[F1[x], Y]]) => R
): R
}