aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-22 17:47:57 +0100
committerMartin Odersky <odersky@gmail.com>2015-11-22 18:03:17 +0100
commite7fdb416006cfa4091b90935c74b5602adb5f68e (patch)
tree1070807d8eb3d3b37cc6047f5362543557bbfec8 /src/dotty/tools
parentdce7053f3a6b859733253edcc82ad42b6ea3ed73 (diff)
downloaddotty-e7fdb416006cfa4091b90935c74b5602adb5f68e.tar.gz
dotty-e7fdb416006cfa4091b90935c74b5602adb5f68e.tar.bz2
dotty-e7fdb416006cfa4091b90935c74b5602adb5f68e.zip
Swap order of arguments in annotations
The fact that the annotation comes first is weird, because when I write an annotated type it's <type> @<annotation>. Also, annotated types are like RefinedTypes in that they derive from a parent type. And in RefinedTypes the parent comes first. So swapping the arguments improves consistency.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/backend/jvm/DottyBackendInterface.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala27
-rw-r--r--src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala3
-rw-r--r--src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala5
-rw-r--r--src/dotty/tools/dotc/printing/PlainPrinter.scala2
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala2
-rw-r--r--src/dotty/tools/dotc/typer/TypeAssigner.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala2
-rw-r--r--src/dotty/tools/dotc/typer/VarianceChecker.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Variances.scala4
13 files changed, 27 insertions, 30 deletions
diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
index 1498be354..f70143888 100644
--- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
+++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
@@ -843,7 +843,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
* meta-annotated annotations (@(ann @getter) val x = 0), so we don't emit a warning.
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
*/
- case a @ AnnotatedType(_, t) =>
+ case a @ AnnotatedType(t, _) =>
debuglog(s"typeKind of annotated type $a")
t.toTypeKind(ct)(storage)
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index 8f116c85f..7cca37911 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -44,7 +44,7 @@ object TypeErasure {
true
case JavaArrayType(elem) =>
isErasedType(elem)
- case AnnotatedType(_, tp) =>
+ case AnnotatedType(tp, _) =>
isErasedType(tp)
case ThisType(tref) =>
isErasedType(tref)
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 4cfc52909..f3884e11a 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -482,7 +482,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
normalizeToRef(tp1)
case ErrorType =>
defn.AnyType
- case AnnotatedType(_, tpe) =>
+ case AnnotatedType(tpe, _) =>
normalizeToRef(tpe)
case _ =>
throw new TypeError(s"unexpected parent type: $tp")
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index db518d959..2558dcbb7 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -176,7 +176,7 @@ object Types {
/** Does the type carry an annotation that is an instance of `cls`? */
final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {
- case AnnotatedType(annot, tp) => (annot matches cls) || (tp hasAnnotation cls)
+ case AnnotatedType(tp, annot) => (annot matches cls) || (tp hasAnnotation cls)
case _ => false
}
@@ -758,7 +758,7 @@ object Types {
case tp: LazyRef =>
tp.ref.dealias
case tp: AnnotatedType =>
- tp.derivedAnnotatedType(tp.annot, tp.tpe.dealias)
+ tp.derivedAnnotatedType(tp.tpe.dealias, tp.annot)
case tp => tp
}
@@ -2197,7 +2197,7 @@ object Types {
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
def translateRepeated(tp: Type): Type = tp match {
case tp @ ExprType(tp1) => tp.derivedExprType(translateRepeated(tp1))
- case AnnotatedType(annot, tp) if annot matches defn.RepeatedAnnot =>
+ case AnnotatedType(tp, annot) if annot matches defn.RepeatedAnnot =>
val typeSym = tp.typeSymbol.asClass
assert(typeSym == defn.SeqClass || typeSym == defn.ArrayClass)
tp.translateParameterized(typeSym, defn.RepeatedParamClass)
@@ -2787,23 +2787,22 @@ object Types {
// ----- Annotated and Import types -----------------------------------------------
/** An annotated type tpe @ annot */
- case class AnnotatedType(annot: Annotation, tpe: Type)
+ case class AnnotatedType(tpe: Type, annot: Annotation)
extends UncachedProxyType with ValueType {
// todo: cache them? but this makes only sense if annotations and trees are also cached.
override def underlying(implicit ctx: Context): Type = tpe
- def derivedAnnotatedType(annot: Annotation, tpe: Type) =
- if ((annot eq this.annot) && (tpe eq this.tpe)) this
- else AnnotatedType(annot, tpe)
+ def derivedAnnotatedType(tpe: Type, annot: Annotation) =
+ if ((tpe eq this.tpe) && (annot eq this.annot)) this
+ else AnnotatedType(tpe, annot)
override def stripTypeVar(implicit ctx: Context): Type =
- derivedAnnotatedType(annot, tpe.stripTypeVar)
+ derivedAnnotatedType(tpe.stripTypeVar, annot)
override def stripAnnots(implicit ctx: Context): Type = tpe.stripAnnots
}
object AnnotatedType {
- def make(annots: List[Annotation], underlying: Type) =
- if (annots.isEmpty) underlying
- else (underlying /: annots)((tp, ann) => AnnotatedType(ann, tp))
+ def make(underlying: Type, annots: List[Annotation]) =
+ (underlying /: annots)(AnnotatedType(_, _))
}
// Special type objects and classes -----------------------------------------------------
@@ -2997,9 +2996,9 @@ object Types {
case tp: SkolemType =>
tp.derivedSkolemType(this(tp.info))
- case tp @ AnnotatedType(annot, underlying) =>
+ case tp @ AnnotatedType(underlying, annot) =>
val underlying1 = this(underlying)
- if (underlying1 eq underlying) tp else tp.derivedAnnotatedType(mapOver(annot), underlying1)
+ if (underlying1 eq underlying) tp else tp.derivedAnnotatedType(underlying1, mapOver(annot))
case tp @ WildcardType =>
tp.derivedWildcardType(mapOver(tp.optBounds))
@@ -3139,7 +3138,7 @@ object Types {
case tp: SkolemType =>
this(x, tp.info)
- case AnnotatedType(annot, underlying) =>
+ case AnnotatedType(underlying, annot) =>
this(applyToAnnot(x, annot), underlying)
case tp: TypeVar =>
diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
index 552d931d7..a59d04210 100644
--- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
@@ -199,7 +199,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
else 0
TypeAlias(alias, variance)
case ANNOTATED =>
- AnnotatedType(Annotation(readTerm()), readType())
+ val annot = Annotation(readTerm())
+ AnnotatedType(readType(), annot)
case ANDtype =>
AndType(readType(), readType())
case ORtype =>
diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
index d14423b7b..cf7b487bb 100644
--- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
+++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
@@ -800,10 +800,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val boundSyms = until(end, readSymbolRef)
elimExistentials(boundSyms, restpe)
case ANNOTATEDtpe =>
- val tp = readTypeRef()
- // no annotation self type is supported, so no test whether this is a symbol ref
- val annots = until(end, readAnnotationRef)
- AnnotatedType.make(annots, tp)
+ AnnotatedType.make(readTypeRef(), until(end, readAnnotationRef))
case _ =>
noSuchTypeTag(tag, end)
}
diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala
index 8b2d68570..0d925a27d 100644
--- a/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -158,7 +158,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
}
case PolyParam(pt, n) =>
toText(polyParamName(pt.paramNames(n))) ~ polyHash(pt)
- case AnnotatedType(annot, tpe) =>
+ case AnnotatedType(tpe, annot) =>
toTextLocal(tpe) ~ " " ~ toText(annot)
case tp: TypeVar =>
if (tp.isInstantiated)
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 221d097f9..75c98ae8a 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -190,7 +190,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
case tree: TypeTree =>
tree.withType(
tree.tpe match {
- case AnnotatedType(annot, tpe) => AnnotatedType(transformAnnot(annot), tpe)
+ case AnnotatedType(tpe, annot) => AnnotatedType(tpe, transformAnnot(annot))
case tpe => tpe
}
)
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index ac4ad1b35..1e8dcf4b2 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -179,7 +179,7 @@ object Inferencing {
/** Recursively widen and also follow type declarations and type aliases. */
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
case tp: TypeRef if !tp.symbol.isClass => widenForMatchSelector(tp.info.bounds.hi)
- case tp: AnnotatedType => tp.derivedAnnotatedType(tp.annot, widenForMatchSelector(tp.tpe))
+ case tp: AnnotatedType => tp.derivedAnnotatedType(widenForMatchSelector(tp.tpe), tp.annot)
case tp => tp
}
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala
index f7cda1ef6..30d6baf8a 100644
--- a/src/dotty/tools/dotc/typer/TypeAssigner.scala
+++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala
@@ -404,7 +404,7 @@ trait TypeAssigner {
tree.withType(sym.nonMemberTermRef)
def assignType(tree: untpd.Annotated, annot: Tree, arg: Tree)(implicit ctx: Context) =
- tree.withType(AnnotatedType(Annotation(annot), arg.tpe))
+ tree.withType(AnnotatedType(arg.tpe, Annotation(annot)))
def assignType(tree: untpd.PackageDef, pid: Tree)(implicit ctx: Context) =
tree.withType(pid.symbol.valRef)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 0ae04cbe8..3f5c4f47e 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1051,7 +1051,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
if (ctx.mode is Mode.Type)
assignType(cpy.Annotated(tree)(annot1, arg1), annot1, arg1)
else {
- val tpt = TypeTree(AnnotatedType(Annotation(annot1), arg1.tpe.widen))
+ val tpt = TypeTree(AnnotatedType(arg1.tpe.widen, Annotation(annot1)))
assignType(cpy.Typed(tree)(arg1, tpt), tpt)
}
}
diff --git a/src/dotty/tools/dotc/typer/VarianceChecker.scala b/src/dotty/tools/dotc/typer/VarianceChecker.scala
index 5d3bd4f20..86b1676c5 100644
--- a/src/dotty/tools/dotc/typer/VarianceChecker.scala
+++ b/src/dotty/tools/dotc/typer/VarianceChecker.scala
@@ -90,7 +90,7 @@ class VarianceChecker()(implicit ctx: Context) {
this(status, tp.resultType) // params will be checked in their TypeDef nodes.
case tp: PolyType =>
this(status, tp.resultType) // params will be checked in their ValDef nodes.
- case AnnotatedType(annot, _) if annot.symbol == defn.UncheckedVarianceAnnot =>
+ case AnnotatedType(_, annot) if annot.symbol == defn.UncheckedVarianceAnnot =>
status
//case tp: ClassInfo =>
// ??? not clear what to do here yet. presumably, it's all checked at local typedefs
diff --git a/src/dotty/tools/dotc/typer/Variances.scala b/src/dotty/tools/dotc/typer/Variances.scala
index 0cc9e74cc..55e6b5232 100644
--- a/src/dotty/tools/dotc/typer/Variances.scala
+++ b/src/dotty/tools/dotc/typer/Variances.scala
@@ -83,8 +83,8 @@ object Variances {
varianceInType(restpe)(tparam)
case tp @ PolyType(_) =>
flip(varianceInTypes(tp.paramBounds)(tparam)) & varianceInType(tp.resultType)(tparam)
- case AnnotatedType(annot, tp) =>
- varianceInAnnot(annot)(tparam) & varianceInType(tp)(tparam)
+ case AnnotatedType(tp, annot) =>
+ varianceInType(tp)(tparam) & varianceInAnnot(annot)(tparam)
case tp: AndOrType =>
varianceInType(tp.tp1)(tparam) & varianceInType(tp.tp2)(tparam)
case _ =>