@@ -7,6 +7,7 @@ import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, F
7
7
import SymDenotations ._ , Symbols ._ , StdNames ._ , Annotations ._ , Trees ._
8
8
import Decorators ._
9
9
import language .higherKinds
10
+ import typer .FrontEnd
10
11
import collection .mutable .ListBuffer
11
12
import util .Property
12
13
import reporting .diagnostic .messages ._
@@ -363,7 +364,7 @@ object desugar {
363
364
if (mods.is(Abstract ) || hasRepeatedParam) Nil // cannot have default arguments for repeated parameters, hence copy method is not issued
364
365
else {
365
366
def copyDefault (vparam : ValDef ) =
366
- makeAnnotated(defn. UncheckedVarianceAnnot , refOfDef(vparam))
367
+ makeAnnotated(" scala.annotation.unchecked.uncheckedVariance " , refOfDef(vparam))
367
368
val copyFirstParams = derivedVparamss.head.map(vparam =>
368
369
cpy.ValDef (vparam)(rhs = copyDefault(vparam)))
369
370
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
@@ -559,7 +560,7 @@ object desugar {
559
560
case VarPattern (named, tpt) =>
560
561
derivedValDef(original, named, tpt, rhs, mods)
561
562
case _ =>
562
- val rhsUnchecked = makeAnnotated(defn. UncheckedAnnot , rhs)
563
+ val rhsUnchecked = makeAnnotated(" scala.unchecked " , rhs)
563
564
val vars = getVariables(pat)
564
565
val isMatchingTuple : Tree => Boolean = {
565
566
case Tuple (es) => es.length == vars.length
@@ -688,11 +689,28 @@ object desugar {
688
689
new ImplicitFunction (params, body)
689
690
}
690
691
691
- /** Add annotation with class `cls` to tree:
692
- * tree @cls
692
+ /** Add annotation to tree:
693
+ * tree @fullName
694
+ *
695
+ * The annotation is usually represented as a TypeTree referring to the class
696
+ * with the given name `fullName`. However, if the annotation matches a file name
697
+ * that is still to be entered, the annotation is represented as a cascade of `Selects`
698
+ * following `fullName`. This is necessary so that we avoid reading an annotation from
699
+ * the classpath that is also compiled from source.
693
700
*/
694
- def makeAnnotated (cls : Symbol , tree : Tree )(implicit ctx : Context ) =
695
- Annotated (tree, untpd.New (untpd.TypeTree (cls.typeRef), Nil ))
701
+ def makeAnnotated (fullName : String , tree : Tree )(implicit ctx : Context ) = {
702
+ val parts = fullName.split('.' )
703
+ val ttree = ctx.typerPhase match {
704
+ case phase : FrontEnd if phase.stillToBeEntered(parts.last) =>
705
+ val prefix =
706
+ ((Ident (nme.ROOTPKG ): Tree ) /: parts.init)((qual, name) =>
707
+ Select (qual, name.toTermName))
708
+ Select (prefix, parts.last.toTypeName)
709
+ case _ =>
710
+ TypeTree (ctx.requiredClass(fullName).typeRef)
711
+ }
712
+ Annotated (tree, untpd.New (ttree, Nil ))
713
+ }
696
714
697
715
private def derivedValDef (original : Tree , named : NameTree , tpt : Tree , rhs : Tree , mods : Modifiers )(implicit ctx : Context ) = {
698
716
val vdef = ValDef (named.name.asTermName, tpt, rhs)
0 commit comments