Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The constraint type of the type parameter supports specialization, and there are `specialized` annotation. It should support specialization.

scala/bug#11489
  • Loading branch information
jxnu-liguobin committed Oct 27, 2022
1 parent 98972e5 commit 959ca84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
Expand Up @@ -506,8 +506,15 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
else if (!args.isEmpty)
enteringTyper {
foreach2(sym.typeParams, args) { (tp, arg) =>
if (tp.isSpecialized)
if (tp.isSpecialized) {
specializedTypeVarsBuffer(arg, result)
} else if (sym == ValueOfClass) { // scala/bug#11489, we only update it for ValueOf
arg.typeSymbol.annotations.foreach {
case lzai: LazyAnnotationInfo if lzai.symbol == SpecializedClass =>
specializedTypeVarsBuffer(arg, result)
case _ =>
}
}
}
}
case PolyType(tparams, resTpe) => specializedTypeVarsBuffer(resTpe, result); tparams.foreach(sym => specializedTypeVarsBuffer(sym.info, result))
Expand Down
8 changes: 8 additions & 0 deletions test/files/specialized/t11489.scala
@@ -0,0 +1,8 @@
class Parent {
def twice[@scala.specialized(Int) I <: Int : ValueOf]: Int = valueOf[I] * 2
}

object Test extends App {
val actualMethods = (new Parent).getClass.getDeclaredMethods
assert(actualMethods.count(_.getName == "twice$mIc$sp") == 1)
}

0 comments on commit 959ca84

Please sign in to comment.