summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-01-15 12:25:41 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-01-15 12:32:36 +0100
commit07ff3a99b75174c4e4a4e52348b34aa0b68f51b1 (patch)
treede5bbfbbc7ddde80ae5b1a97a6a8f6b6560da8af /src/compiler/scala/tools/nsc/typechecker
parente089cafb5fd02e2457bafde3252da3a771d3180e (diff)
downloadscala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.tar.gz
scala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.tar.bz2
scala-07ff3a99b75174c4e4a4e52348b34aa0b68f51b1.zip
SI-8151 Remove -Yself-in-annots and associated implementation
This experimental option typechecked arguments of annotations with an injected value in scope named `self`: @Foo(self.foo < 1) This has been slated for removal [1] for some time. This commit removes it in one fell swoop, without any attempt at source compatibility with code that constructs or pattern matches on AnnotatedType. [1] https://groups.google.com/d/msg/scala-internals/VdZ5UJwQFGI/C6tZ493Yxx4J
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala62
5 files changed, 13 insertions, 61 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
index 73572bcae9..1f1ccbe359 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
@@ -180,7 +180,7 @@ trait DestructureTypes {
case SuperType(thistp, supertp) => product(tp, this("this", thistp), this("super", supertp))
case ThisType(clazz) => product(tp, wrapAtom(clazz))
case TypeVar(inst, constr) => product(tp, this("inst", inst), typeConstraint(constr))
- case AnnotatedType(annotations, underlying, _) => annotatedType(annotations, underlying)
+ case AnnotatedType(annotations, underlying) => annotatedType(annotations, underlying)
case ExistentialType(tparams, underlying) => polyFunction(tparams, underlying)
case PolyType(tparams, restpe) => polyFunction(tparams, restpe)
case MethodType(params, restpe) => monoFunction(params, restpe)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index fdec1edcc0..1916a18ea1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -389,7 +389,7 @@ trait Implicits {
private def dominates(dtor: Type, dted: Type): Boolean = {
def core(tp: Type): Type = tp.dealiasWiden match {
case RefinedType(parents, defs) => intersectionType(parents map core, tp.typeSymbol.owner)
- case AnnotatedType(annots, tp, selfsym) => core(tp)
+ case AnnotatedType(annots, tp) => core(tp)
case ExistentialType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
case PolyType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
case _ => tp
@@ -1060,7 +1060,7 @@ trait Implicits {
getParts(restpe)
case RefinedType(ps, _) =>
for (p <- ps) getParts(p)
- case AnnotatedType(_, t, _) =>
+ case AnnotatedType(_, t) =>
getParts(t)
case ExistentialType(_, t) =>
getParts(t)
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 95f2620061..330dc0434b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1431,7 +1431,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
private def checkTypeRefBounds(tp: Type, tree: Tree) = {
var skipBounds = false
tp match {
- case AnnotatedType(ann :: Nil, underlying, selfSym) if ann.symbol == UncheckedBoundsClass =>
+ case AnnotatedType(ann :: Nil, underlying) if ann.symbol == UncheckedBoundsClass =>
skipBounds = true
underlying
case TypeRef(pre, sym, args) =>
@@ -1474,7 +1474,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
}
doTypeTraversal(tree) {
- case tp @ AnnotatedType(annots, _, _) =>
+ case tp @ AnnotatedType(annots, _) =>
applyChecks(annots)
case tp =>
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index b706e1af6b..06796eca8e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -542,7 +542,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
case TypeRef(pre, _, _) => isThisType(pre)
case SingleType(pre, _) => isThisType(pre)
case RefinedType(parents, _) => parents exists isThisType
- case AnnotatedType(_, tp, _) => isThisType(tp)
+ case AnnotatedType(_, tp) => isThisType(tp)
case _ => false
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6b5afce993..c8e634eb4c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1122,7 +1122,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (treeInfo.isMacroApplication(tree)) adapt(unmarkMacroImplRef(tree), mode, pt, original)
else tree
} else tree.tpe match {
- case atp @ AnnotatedType(_, _, _) if canAdaptAnnotations(tree, this, mode, pt) => // (-1)
+ case atp @ AnnotatedType(_, _) if canAdaptAnnotations(tree, this, mode, pt) => // (-1)
adaptAnnotations(tree, this, mode, pt)
case ct @ ConstantType(value) if mode.inNone(TYPEmode | FUNmode) && (ct <:< pt) && canAdaptConstantTypeToLiteral => // (0)
adaptConstant(value)
@@ -3470,7 +3470,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
/**
* Convert an annotation constructor call into an AnnotationInfo.
*/
- def typedAnnotation(ann: Tree, mode: Mode = EXPRmode, selfsym: Symbol = NoSymbol): AnnotationInfo = {
+ def typedAnnotation(ann: Tree, mode: Mode = EXPRmode): AnnotationInfo = {
var hasError: Boolean = false
val pending = ListBuffer[AbsTypeError]()
@@ -3519,7 +3519,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
reportAnnotationError(ArrayConstantsError(tree)); None
case ann @ Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
- val annInfo = typedAnnotation(ann, mode, NoSymbol)
+ val annInfo = typedAnnotation(ann, mode)
val annType = annInfo.tpe
if (!annType.typeSymbol.isSubClass(pt.typeSymbol))
@@ -3631,28 +3631,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
}
else {
- val typedAnn = if (selfsym == NoSymbol) {
+ val typedAnn: Tree = {
// local dummy fixes SI-5544
val localTyper = newTyper(context.make(ann, context.owner.newLocalDummy(ann.pos)))
localTyper.typed(ann, mode, annType)
}
- else {
- // Since a selfsym is supplied, the annotation should have an extra
- // "self" identifier in scope for type checking. This is implemented
- // by wrapping the rhs in a function like "self => rhs" during type
- // checking, and then stripping the "self =>" and substituting in
- // the supplied selfsym.
- val funcparm = ValDef(NoMods, nme.self, TypeTree(selfsym.info), EmptyTree)
- // The .duplicate of annot.constr deals with problems that accur
- // if this annotation is later typed again, which the compiler
- // sometimes does. The problem is that "self" ident's within
- // annot.constr will retain the old symbol from the previous typing.
- val func = Function(funcparm :: Nil, ann.duplicate)
- val funcType = appliedType(FunctionClass(1), selfsym.info, annType)
- val Function(arg :: Nil, rhs) = typed(func, mode, funcType)
-
- rhs.substituteSymbols(arg.symbol :: Nil, selfsym :: Nil)
- }
def annInfo(t: Tree): AnnotationInfo = t match {
case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
AnnotationInfo(annType, args, List()).setOriginal(typedAnn).setPos(t.pos)
@@ -3770,7 +3753,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
t match {
case ExistentialType(tparams, _) =>
boundSyms ++= tparams
- case AnnotatedType(annots, _, _) =>
+ case AnnotatedType(annots, _) =>
for (annot <- annots; arg <- annot.args) {
arg match {
case Ident(_) =>
@@ -4035,39 +4018,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (arg1.isType) {
// make sure the annotation is only typechecked once
if (ann.tpe == null) {
- // an annotated type
- val selfsym =
- if (!settings.selfInAnnots)
- NoSymbol
- else
- arg1.tpe.selfsym orElse {
- /* Implementation limitation: Currently this
- * can cause cyclical reference errors even
- * when the self symbol is not referenced at all.
- * Surely at least some of these cases can be
- * fixed by proper use of LazyType's. Lex tinkered
- * on this but did not succeed, so is leaving
- * it alone for now. Example code with the problem:
- * class peer extends Annotation
- * class NPE[T <: NPE[T] @peer]
- *
- * (Note: -Yself-in-annots must be on to see the problem)
- * */
- ( context.owner
- newLocalDummy (ann.pos)
- newValue (nme.self, ann.pos)
- setInfo (arg1.tpe.withoutAnnotations)
- )
- }
-
- val ainfo = typedAnnotation(ann, annotMode, selfsym)
- val atype0 = arg1.tpe.withAnnotation(ainfo)
- val atype =
- if ((selfsym != NoSymbol) && (ainfo.refsSymbol(selfsym)))
- atype0.withSelfsym(selfsym)
- else
- atype0 // do not record selfsym if
- // this annotation did not need it
+ val ainfo = typedAnnotation(ann, annotMode)
+ val atype = arg1.tpe.withAnnotation(ainfo)
if (ainfo.isErroneous)
// Erroneous annotations were already reported in typedAnnotation