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

Handle higher-kinded type parameters in SpecializeTypes #9439

Merged
merged 1 commit into from Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
Expand Up @@ -641,7 +641,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
// log("new tparams " + newClassTParams.zip(newClassTParams map {s => (s.tpe, s.tpe.upperBound)}) + ", in env: " + env)

def applyContext(tpe: Type) =
subst(env, tpe).instantiateTypeParams(oldClassTParams, newClassTParams map (_.tpe))
subst(env, tpe).instantiateTypeParams(oldClassTParams, newClassTParams.map(_.tpeHK))

/* Return a list of specialized parents to be re-mixed in a specialized subclass.
* Assuming env = [T -> Int] and
Expand Down Expand Up @@ -699,7 +699,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*/
def enterMember(sym: Symbol): Symbol = {
typeEnv(sym) = fullEnv ++ typeEnv(sym) // append the full environment
sym.modifyInfo(_.substThis(clazz, sClass).instantiateTypeParams(oldClassTParams, newClassTParams.map(_.tpe)))
sym.modifyInfo(_.substThis(clazz, sClass).instantiateTypeParams(oldClassTParams, newClassTParams.map(_.tpeHK)))
// we remove any default parameters. At this point, they have been all
// resolved by the type checker. Later on, erasure re-typechecks everything and
// chokes if it finds default parameters for specialized members, even though
Expand Down Expand Up @@ -951,7 +951,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
tps1 foreach (_ modifyInfo (_.instantiateTypeParams(keys, vals)))

// the cloneInfo is necessary so that method parameter symbols are cloned at the new owner
val methodType = sym.info.resultType.instantiateTypeParams(keys ++ tps, vals ++ tps1.map(_.tpe)).cloneInfo(specMember)
val methodType = sym.info.resultType.instantiateTypeParams(keys ++ tps, vals ++ tps1.map(_.tpeHK)).cloneInfo(specMember)
specMember setInfo GenPolyType(tps1, methodType)

debuglog("%s expands to %s in %s".format(sym, specMember.name.decode, pp(env)))
Expand Down
6 changes: 6 additions & 0 deletions test/files/pos/t9227.scala
@@ -0,0 +1,6 @@
trait TC[M[_], @specialized(Int) A]

object Test {
def f2[M[_], @specialized(Int) A](implicit ev: TC[M, A]): M[A] = ???
def f1[M[_], @specialized(Int) A](implicit ev: TC[M, A]): M[A] = f2[M, A](ev)
}