Skip to content

Commit 331e75b

Browse files
committed
Swap order of elements in Annotated
Now it's annotated first, annotation second. This is in line with AnnotatedType and in line with the principle that tree arguments should come in the order they are written. The reason why the order was swapped before is historical - Scala2 did it that way.
1 parent fb71045 commit 331e75b

File tree

13 files changed

+32
-32
lines changed

13 files changed

+32
-32
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ object desugar {
632632
val selector = makeTuple(params.map(p => Ident(p.name)))
633633

634634
if (unchecked)
635-
Function(params, Match(Annotated(New(ref(defn.UncheckedAnnotType)), selector), cases))
635+
Function(params, Match(Annotated(selector, New(ref(defn.UncheckedAnnotType))), cases))
636636
else
637637
Function(params, Match(selector, cases))
638638
}
@@ -661,7 +661,7 @@ object desugar {
661661
* tree @cls
662662
*/
663663
def makeAnnotated(cls: Symbol, tree: Tree)(implicit ctx: Context) =
664-
Annotated(untpd.New(untpd.TypeTree(cls.typeRef), Nil), tree)
664+
Annotated(tree, untpd.New(untpd.TypeTree(cls.typeRef), Nil))
665665

666666
private def derivedValDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(implicit ctx: Context) = {
667667
val vdef = ValDef(named.name.asTermName, tpt, rhs)
@@ -904,8 +904,8 @@ object desugar {
904904
if ((ctx.mode is Mode.Type) && op == nme.raw.STAR) {
905905
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
906906
Annotated(
907-
New(ref(defn.RepeatedAnnotType), Nil :: Nil),
908-
AppliedTypeTree(ref(seqType), t))
907+
AppliedTypeTree(ref(seqType), t),
908+
New(ref(defn.RepeatedAnnotType), Nil :: Nil))
909909
} else {
910910
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
911911
Select(t, op)
@@ -1052,7 +1052,7 @@ object desugar {
10521052
case Alternative(trees) =>
10531053
for (tree <- trees; (vble, _) <- getVariables(tree))
10541054
ctx.error("illegal variable in pattern alternative", vble.pos)
1055-
case Annotated(annot, arg) =>
1055+
case Annotated(arg, _) =>
10561056
collect(arg)
10571057
case InterpolatedString(_, _, elems) =>
10581058
elems foreach collect

src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
183183
case RefinedTypeTree(tpt, refinements) => mayBeTypePat(tpt) || refinements.exists(_.isInstanceOf[Bind])
184184
case AppliedTypeTree(tpt, args) => mayBeTypePat(tpt) || args.exists(_.isInstanceOf[Bind])
185185
case SelectFromTypeTree(tpt, _) => mayBeTypePat(tpt)
186-
case Annotated(_, tpt) => mayBeTypePat(tpt)
186+
case Annotated(tpt, _) => mayBeTypePat(tpt)
187187
case _ => false
188188
}
189189

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ object Trees {
709709
}
710710

711711
/** arg @annot */
712-
case class Annotated[-T >: Untyped] private[ast] (annot: Tree[T], arg: Tree[T])
712+
case class Annotated[-T >: Untyped] private[ast] (arg: Tree[T], annot: Tree[T])
713713
extends ProxyTree[T] {
714714
type ThisTree[-T >: Untyped] = Annotated[T]
715715
def forwardTo = arg
@@ -1082,9 +1082,9 @@ object Trees {
10821082
case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree
10831083
case _ => finalize(tree, untpd.PackageDef(pid, stats))
10841084
}
1085-
def Annotated(tree: Tree)(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = tree match {
1086-
case tree: Annotated if (annot eq tree.annot) && (arg eq tree.arg) => tree
1087-
case _ => finalize(tree, untpd.Annotated(annot, arg))
1085+
def Annotated(tree: Tree)(arg: Tree, annot: Tree)(implicit ctx: Context): Annotated = tree match {
1086+
case tree: Annotated if (arg eq tree.arg) && (annot eq tree.annot) => tree
1087+
case _ => finalize(tree, untpd.Annotated(arg, annot))
10881088
}
10891089
def Thicket(tree: Tree)(trees: List[Tree]): Thicket = tree match {
10901090
case tree: Thicket if trees eq tree.trees => tree
@@ -1198,8 +1198,8 @@ object Trees {
11981198
cpy.Import(tree)(transform(expr), selectors)
11991199
case PackageDef(pid, stats) =>
12001200
cpy.PackageDef(tree)(transformSub(pid), transformStats(stats))
1201-
case Annotated(annot, arg) =>
1202-
cpy.Annotated(tree)(transform(annot), transform(arg))
1201+
case Annotated(arg, annot) =>
1202+
cpy.Annotated(tree)(transform(arg), transform(annot))
12031203
case Thicket(trees) =>
12041204
val trees1 = transform(trees)
12051205
if (trees1 eq trees) tree else Thicket(trees1)
@@ -1304,8 +1304,8 @@ object Trees {
13041304
this(x, expr)
13051305
case PackageDef(pid, stats) =>
13061306
this(this(x, pid), stats)(localCtx)
1307-
case Annotated(annot, arg) =>
1308-
this(this(x, annot), arg)
1307+
case Annotated(arg, annot) =>
1308+
this(this(x, arg), annot)
13091309
case Thicket(ts) =>
13101310
this(x, ts)
13111311
}

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
292292
def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
293293
ta.assignType(untpd.PackageDef(pid, stats), pid)
294294

295-
def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated =
296-
ta.assignType(untpd.Annotated(annot, arg), annot, arg)
295+
def Annotated(arg: Tree, annot: Tree)(implicit ctx: Context): Annotated =
296+
ta.assignType(untpd.Annotated(arg, annot), arg, annot)
297297

298298
def Throw(expr: Tree)(implicit ctx: Context): Tree =
299299
ref(defn.throwMethod).appliedTo(expr)
@@ -568,11 +568,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
568568
}
569569
}
570570

571-
override def Annotated(tree: Tree)(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = {
572-
val tree1 = untpd.cpy.Annotated(tree)(annot, arg)
571+
override def Annotated(tree: Tree)(arg: Tree, annot: Tree)(implicit ctx: Context): Annotated = {
572+
val tree1 = untpd.cpy.Annotated(tree)(arg, annot)
573573
tree match {
574574
case tree: Annotated if (arg.tpe eq tree.arg.tpe) && (annot eq tree.annot) => tree1.withTypeUnchecked(tree.tpe)
575-
case _ => ta.assignType(tree1, annot, arg)
575+
case _ => ta.assignType(tree1, arg, annot)
576576
}
577577
}
578578

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
159159
def Template(constr: DefDef, parents: List[Tree], self: ValDef, body: LazyTreeList): Template = new Template(constr, parents, self, body)
160160
def Import(expr: Tree, selectors: List[untpd.Tree]): Import = new Import(expr, selectors)
161161
def PackageDef(pid: RefTree, stats: List[Tree]): PackageDef = new PackageDef(pid, stats)
162-
def Annotated(annot: Tree, arg: Tree): Annotated = new Annotated(annot, arg)
162+
def Annotated(arg: Tree, annot: Tree): Annotated = new Annotated(arg, annot)
163163

164164
// ------ Additional creation methods for untyped only -----------------
165165

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11861186
case ANNOTATEDtree =>
11871187
val annot = readTreeRef()
11881188
val arg = readTreeRef()
1189-
Annotated(annot, arg)
1189+
Annotated(arg, annot)
11901190

11911191
case SINGLETONTYPEtree =>
11921192
SingletonTypeTree(readTreeRef())

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ object Parsers {
338338
def isWildcard(t: Tree): Boolean = t match {
339339
case Ident(name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name
340340
case Typed(t1, _) => isWildcard(t1)
341-
case t: Annotated => isWildcard(t.arg)
341+
case Annotated(t1, _) => isWildcard(t1)
342342
case Parens(t1) => isWildcard(t1)
343343
case _ => false
344344
}
@@ -742,7 +742,7 @@ object Parsers {
742742
def annotType(): Tree = annotTypeRest(simpleType())
743743

744744
def annotTypeRest(t: Tree): Tree =
745-
if (in.token == AT) annotTypeRest(atPos(t.pos.start) { Annotated(annot(), t) })
745+
if (in.token == AT) annotTypeRest(atPos(t.pos.start) { Annotated(t, annot()) })
746746
else t
747747

748748
/** SimpleType ::= SimpleType TypeArgs
@@ -900,7 +900,7 @@ object Parsers {
900900
private final def findWildcardType(t: Tree): Option[Position] = t match {
901901
case TypeBoundsTree(_, _) => Some(t.pos)
902902
case Parens(t1) => findWildcardType(t1)
903-
case Annotated(_, t1) => findWildcardType(t1)
903+
case Annotated(t1, _) => findWildcardType(t1)
904904
case _ => None
905905
}
906906

@@ -1071,7 +1071,7 @@ object Parsers {
10711071
syntaxErrorOrIncomplete("`*' expected"); t
10721072
}
10731073
case AT if location != Location.InPattern =>
1074-
(t /: annotations()) ((t, annot) => Annotated(annot, t))
1074+
(t /: annotations())(Annotated)
10751075
case _ =>
10761076
val tpt = typeDependingOn(location)
10771077
if (isWildcard(t) && location != Location.InPattern) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
434434
"package " ~ toTextPackageId(pid) ~ bodyText
435435
case tree: Template =>
436436
toTextTemplate(tree)
437-
case Annotated(annot, arg) =>
437+
case Annotated(arg, annot) =>
438438
toTextLocal(arg) ~~ annotText(annot)
439439
case EmptyTree =>
440440
"<empty>"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
7474
Bind(defaultSym, Underscore(selector.tpe.widen)),
7575
EmptyTree,
7676
Literal(Constant(false)))
77-
val annotated = Annotated(New(ref(defn.UncheckedAnnotType)), paramRef)
77+
val annotated = Annotated(paramRef, New(ref(defn.UncheckedAnnotType)))
7878
cpy.Match(applyRhs)(annotated, cases.map(translateCase) :+ defaultCase)
7979
case _ =>
8080
tru

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
262262
case tree: New if !inJavaAnnot && !parentNews.contains(tree) =>
263263
Checking.checkInstantiable(tree.tpe, tree.pos)
264264
super.transform(tree)
265-
case tree @ Annotated(annot, annotated) =>
266-
cpy.Annotated(tree)(transformAnnot(annot), transform(annotated))
265+
case tree @ Annotated(annotated, annot) =>
266+
cpy.Annotated(tree)(transform(annotated), transformAnnot(annot))
267267
case tree: TypeTree =>
268268
tree.withType(
269269
tree.tpe match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class TreeChecker extends Phase with SymTransformer {
252252
// case tree: TypeBoundsTree =>
253253
// case tree: Alternative =>
254254
// case tree: PackageDef =>
255-
case Annotated(_, arg) =>
255+
case Annotated(arg, _) =>
256256
assertIdentNotJavaClass(arg)
257257
case _ =>
258258
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ trait TypeAssigner {
500500
def assignType(tree: untpd.Import, sym: Symbol)(implicit ctx: Context) =
501501
tree.withType(sym.nonMemberTermRef)
502502

503-
def assignType(tree: untpd.Annotated, annot: Tree, arg: Tree)(implicit ctx: Context) =
503+
def assignType(tree: untpd.Annotated, arg: Tree, annot: Tree)(implicit ctx: Context) =
504504
tree.withType(AnnotatedType(arg.tpe.widen, Annotation(annot)))
505505

506506
def assignType(tree: untpd.PackageDef, pid: Tree)(implicit ctx: Context) =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13421342
val annot1 = typedExpr(tree.annot, defn.AnnotationType)
13431343
val arg1 = typed(tree.arg, pt)
13441344
if (ctx.mode is Mode.Type)
1345-
assignType(cpy.Annotated(tree)(annot1, arg1), annot1, arg1)
1345+
assignType(cpy.Annotated(tree)(arg1, annot1), arg1, annot1)
13461346
else {
13471347
val tpt = TypeTree(AnnotatedType(arg1.tpe.widen, Annotation(annot1)))
13481348
assignType(cpy.Typed(tree)(arg1, tpt), tpt)

0 commit comments

Comments
 (0)