Skip to content

Swap order of arguments in annotations #969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 13 additions & 14 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 -----------------------------------------------------
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Standard-Section: "ASTs" TopLevelStat*
APPLIEDtype Length tycon_Type arg_Type*
TYPEBOUNDS Length low_Type high_Type
TYPEALIAS Length alias_Type (COVARIANT | CONTRAVARIANT)?
ANNOTATED Length fullAnnotation_Term underlying_Type
ANNOTATED Length underlying_Type fullAnnotation_Term
ANDtype Length left_Type right_Type
ORtype Length left_Type right_Type
BIND Length boundName_NameRef bounds_Type
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class TreePickler(pickler: TastyPickler) {
withLength { pickleType(tpe.lo, richTypes); pickleType(tpe.hi, richTypes) }
case tpe: AnnotatedType =>
writeByte(ANNOTATED)
withLength { pickleTree(tpe.annot.tree); pickleType(tpe.tpe, richTypes) }
withLength { pickleType(tpe.tpe, richTypes); pickleTree(tpe.annot.tree) }
case tpe: AndOrType =>
writeByte(if (tpe.isAnd) ANDtype else ORtype)
withLength { pickleType(tpe.tp1, richTypes); pickleType(tpe.tp2, richTypes) }
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
else 0
TypeAlias(alias, variance)
case ANNOTATED =>
AnnotatedType(Annotation(readTerm()), readType())
AnnotatedType(readType(), Annotation(readTerm()))
case ANDtype =>
AndType(readType(), readType())
case ORtype =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/VarianceChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/typer/Variances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down