Closed
Description
Annotations on parameter/return types disappear when the type of a polymorphic method is built. This only happens where the annotations have an underlying PolyParam.
trait Annot extends annotation.StaticAnnotation with annotation.TypeConstraint
trait PolyBug {
// This works
type T
def m(param1: T @Annot): T @Annot
// These do not: annotations are dropped
def m1[P](param1: P @Annot): P @Annot
def m2[P](param1: List[P @Annot] @Annot): List[P @Annot] @Annot
// This doesn't work either, but the annotations on T remain intact
def m3[P](param1: Map[P @Annot,T @Annot] @Annot): Map[P @Annot,T @Annot] @Annot
}
In all cases above, the annotations exist on the typed tree. Annotations also exist on the typed tree's type, except for the type of the DefDef tree.
The computed types of the methods above are:
m: (param1: PolyBug.this.T @Annot)PolyBug.this.T @Annot
m1: [P](param1: P)P
m2: [P](param1: scala.collection.immutable.List[P])scala.collection.immutable.List[P]
m3: [P](param1: scala.collection.immutable.Map[P, PolyBug.this.T @Annot])
scala.collection.immutable.Map[P, PolyBug.this.T @Annot]
Annotations still exist on the ValDef trees' types, but they are lost when computing the DefDef trees' types.