Skip to content

Commit e7fdb41

Browse files
committed
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.
1 parent dce7053 commit e7fdb41

File tree

13 files changed

+27
-30
lines changed

13 files changed

+27
-30
lines changed

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
843843
* meta-annotated annotations (@(ann @getter) val x = 0), so we don't emit a warning.
844844
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
845845
*/
846-
case a @ AnnotatedType(_, t) =>
846+
case a @ AnnotatedType(t, _) =>
847847
debuglog(s"typeKind of annotated type $a")
848848
t.toTypeKind(ct)(storage)
849849

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object TypeErasure {
4444
true
4545
case JavaArrayType(elem) =>
4646
isErasedType(elem)
47-
case AnnotatedType(_, tp) =>
47+
case AnnotatedType(tp, _) =>
4848
isErasedType(tp)
4949
case ThisType(tref) =>
5050
isErasedType(tref)

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
482482
normalizeToRef(tp1)
483483
case ErrorType =>
484484
defn.AnyType
485-
case AnnotatedType(_, tpe) =>
485+
case AnnotatedType(tpe, _) =>
486486
normalizeToRef(tpe)
487487
case _ =>
488488
throw new TypeError(s"unexpected parent type: $tp")

src/dotty/tools/dotc/core/Types.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ object Types {
176176

177177
/** Does the type carry an annotation that is an instance of `cls`? */
178178
final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {
179-
case AnnotatedType(annot, tp) => (annot matches cls) || (tp hasAnnotation cls)
179+
case AnnotatedType(tp, annot) => (annot matches cls) || (tp hasAnnotation cls)
180180
case _ => false
181181
}
182182

@@ -758,7 +758,7 @@ object Types {
758758
case tp: LazyRef =>
759759
tp.ref.dealias
760760
case tp: AnnotatedType =>
761-
tp.derivedAnnotatedType(tp.annot, tp.tpe.dealias)
761+
tp.derivedAnnotatedType(tp.tpe.dealias, tp.annot)
762762
case tp => tp
763763
}
764764

@@ -2197,7 +2197,7 @@ object Types {
21972197
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
21982198
def translateRepeated(tp: Type): Type = tp match {
21992199
case tp @ ExprType(tp1) => tp.derivedExprType(translateRepeated(tp1))
2200-
case AnnotatedType(annot, tp) if annot matches defn.RepeatedAnnot =>
2200+
case AnnotatedType(tp, annot) if annot matches defn.RepeatedAnnot =>
22012201
val typeSym = tp.typeSymbol.asClass
22022202
assert(typeSym == defn.SeqClass || typeSym == defn.ArrayClass)
22032203
tp.translateParameterized(typeSym, defn.RepeatedParamClass)
@@ -2787,23 +2787,22 @@ object Types {
27872787
// ----- Annotated and Import types -----------------------------------------------
27882788

27892789
/** An annotated type tpe @ annot */
2790-
case class AnnotatedType(annot: Annotation, tpe: Type)
2790+
case class AnnotatedType(tpe: Type, annot: Annotation)
27912791
extends UncachedProxyType with ValueType {
27922792
// todo: cache them? but this makes only sense if annotations and trees are also cached.
27932793
override def underlying(implicit ctx: Context): Type = tpe
2794-
def derivedAnnotatedType(annot: Annotation, tpe: Type) =
2795-
if ((annot eq this.annot) && (tpe eq this.tpe)) this
2796-
else AnnotatedType(annot, tpe)
2794+
def derivedAnnotatedType(tpe: Type, annot: Annotation) =
2795+
if ((tpe eq this.tpe) && (annot eq this.annot)) this
2796+
else AnnotatedType(tpe, annot)
27972797

27982798
override def stripTypeVar(implicit ctx: Context): Type =
2799-
derivedAnnotatedType(annot, tpe.stripTypeVar)
2799+
derivedAnnotatedType(tpe.stripTypeVar, annot)
28002800
override def stripAnnots(implicit ctx: Context): Type = tpe.stripAnnots
28012801
}
28022802

28032803
object AnnotatedType {
2804-
def make(annots: List[Annotation], underlying: Type) =
2805-
if (annots.isEmpty) underlying
2806-
else (underlying /: annots)((tp, ann) => AnnotatedType(ann, tp))
2804+
def make(underlying: Type, annots: List[Annotation]) =
2805+
(underlying /: annots)(AnnotatedType(_, _))
28072806
}
28082807

28092808
// Special type objects and classes -----------------------------------------------------
@@ -2997,9 +2996,9 @@ object Types {
29972996
case tp: SkolemType =>
29982997
tp.derivedSkolemType(this(tp.info))
29992998

3000-
case tp @ AnnotatedType(annot, underlying) =>
2999+
case tp @ AnnotatedType(underlying, annot) =>
30013000
val underlying1 = this(underlying)
3002-
if (underlying1 eq underlying) tp else tp.derivedAnnotatedType(mapOver(annot), underlying1)
3001+
if (underlying1 eq underlying) tp else tp.derivedAnnotatedType(underlying1, mapOver(annot))
30033002

30043003
case tp @ WildcardType =>
30053004
tp.derivedWildcardType(mapOver(tp.optBounds))
@@ -3139,7 +3138,7 @@ object Types {
31393138
case tp: SkolemType =>
31403139
this(x, tp.info)
31413140

3142-
case AnnotatedType(annot, underlying) =>
3141+
case AnnotatedType(underlying, annot) =>
31433142
this(applyToAnnot(x, annot), underlying)
31443143

31453144
case tp: TypeVar =>

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
199199
else 0
200200
TypeAlias(alias, variance)
201201
case ANNOTATED =>
202-
AnnotatedType(Annotation(readTerm()), readType())
202+
val annot = Annotation(readTerm())
203+
AnnotatedType(readType(), annot)
203204
case ANDtype =>
204205
AndType(readType(), readType())
205206
case ORtype =>

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
800800
val boundSyms = until(end, readSymbolRef)
801801
elimExistentials(boundSyms, restpe)
802802
case ANNOTATEDtpe =>
803-
val tp = readTypeRef()
804-
// no annotation self type is supported, so no test whether this is a symbol ref
805-
val annots = until(end, readAnnotationRef)
806-
AnnotatedType.make(annots, tp)
803+
AnnotatedType.make(readTypeRef(), until(end, readAnnotationRef))
807804
case _ =>
808805
noSuchTypeTag(tag, end)
809806
}

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
158158
}
159159
case PolyParam(pt, n) =>
160160
toText(polyParamName(pt.paramNames(n))) ~ polyHash(pt)
161-
case AnnotatedType(annot, tpe) =>
161+
case AnnotatedType(tpe, annot) =>
162162
toTextLocal(tpe) ~ " " ~ toText(annot)
163163
case tp: TypeVar =>
164164
if (tp.isInstantiated)

src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
190190
case tree: TypeTree =>
191191
tree.withType(
192192
tree.tpe match {
193-
case AnnotatedType(annot, tpe) => AnnotatedType(transformAnnot(annot), tpe)
193+
case AnnotatedType(tpe, annot) => AnnotatedType(tpe, transformAnnot(annot))
194194
case tpe => tpe
195195
}
196196
)

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ object Inferencing {
179179
/** Recursively widen and also follow type declarations and type aliases. */
180180
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
181181
case tp: TypeRef if !tp.symbol.isClass => widenForMatchSelector(tp.info.bounds.hi)
182-
case tp: AnnotatedType => tp.derivedAnnotatedType(tp.annot, widenForMatchSelector(tp.tpe))
182+
case tp: AnnotatedType => tp.derivedAnnotatedType(widenForMatchSelector(tp.tpe), tp.annot)
183183
case tp => tp
184184
}
185185

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ trait TypeAssigner {
404404
tree.withType(sym.nonMemberTermRef)
405405

406406
def assignType(tree: untpd.Annotated, annot: Tree, arg: Tree)(implicit ctx: Context) =
407-
tree.withType(AnnotatedType(Annotation(annot), arg.tpe))
407+
tree.withType(AnnotatedType(arg.tpe, Annotation(annot)))
408408

409409
def assignType(tree: untpd.PackageDef, pid: Tree)(implicit ctx: Context) =
410410
tree.withType(pid.symbol.valRef)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10511051
if (ctx.mode is Mode.Type)
10521052
assignType(cpy.Annotated(tree)(annot1, arg1), annot1, arg1)
10531053
else {
1054-
val tpt = TypeTree(AnnotatedType(Annotation(annot1), arg1.tpe.widen))
1054+
val tpt = TypeTree(AnnotatedType(arg1.tpe.widen, Annotation(annot1)))
10551055
assignType(cpy.Typed(tree)(arg1, tpt), tpt)
10561056
}
10571057
}

src/dotty/tools/dotc/typer/VarianceChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class VarianceChecker()(implicit ctx: Context) {
9090
this(status, tp.resultType) // params will be checked in their TypeDef nodes.
9191
case tp: PolyType =>
9292
this(status, tp.resultType) // params will be checked in their ValDef nodes.
93-
case AnnotatedType(annot, _) if annot.symbol == defn.UncheckedVarianceAnnot =>
93+
case AnnotatedType(_, annot) if annot.symbol == defn.UncheckedVarianceAnnot =>
9494
status
9595
//case tp: ClassInfo =>
9696
// ??? not clear what to do here yet. presumably, it's all checked at local typedefs

src/dotty/tools/dotc/typer/Variances.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ object Variances {
8383
varianceInType(restpe)(tparam)
8484
case tp @ PolyType(_) =>
8585
flip(varianceInTypes(tp.paramBounds)(tparam)) & varianceInType(tp.resultType)(tparam)
86-
case AnnotatedType(annot, tp) =>
87-
varianceInAnnot(annot)(tparam) & varianceInType(tp)(tparam)
86+
case AnnotatedType(tp, annot) =>
87+
varianceInType(tp)(tparam) & varianceInAnnot(annot)(tparam)
8888
case tp: AndOrType =>
8989
varianceInType(tp.tp1)(tparam) & varianceInType(tp.tp2)(tparam)
9090
case _ =>

0 commit comments

Comments
 (0)