aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-11-10 18:29:58 +0100
committerMartin Odersky <odersky@gmail.com>2014-11-10 18:29:58 +0100
commitf7a4d811f769583be13a376a3daedd2eadd31447 (patch)
tree1c82858472d08575dfb6815d9c70cee92095a79a /src/dotty/tools/dotc/typer
parentc9d7eefc0989066e85ca598dff2639d412aabbee (diff)
downloaddotty-f7a4d811f769583be13a376a3daedd2eadd31447.tar.gz
dotty-f7a4d811f769583be13a376a3daedd2eadd31447.tar.bz2
dotty-f7a4d811f769583be13a376a3daedd2eadd31447.zip
Drop modifiers as separate data from MemberDef trees
Typed MemberDef trees now take the modifiers from their symbol's data.
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r--src/dotty/tools/dotc/typer/EtaExpansion.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala12
-rw-r--r--src/dotty/tools/dotc/typer/ReTyper.scala5
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala38
-rw-r--r--src/dotty/tools/dotc/typer/VarianceChecker.scala2
5 files changed, 28 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala
index 394accd03..6ecd90c08 100644
--- a/src/dotty/tools/dotc/typer/EtaExpansion.scala
+++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala
@@ -135,7 +135,7 @@ object EtaExpansion {
if (mt.paramTypes.length == xarity) mt.paramTypes map (_ => TypeTree())
else mt.paramTypes map TypeTree
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
- ValDef(Modifiers(Synthetic | Param), name, TypeTree(tpe), EmptyTree).withPos(tree.pos))
+ ValDef(name, TypeTree(tpe), EmptyTree).withFlags(Synthetic | Param).withPos(tree.pos))
val ids = mt.paramNames map (name =>
Ident(name).withPos(tree.pos))
val body = Apply(lifted, ids)
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index e8bb1b9e7..0ca681d32 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -361,14 +361,14 @@ class Namer { typer: Typer =>
*/
def mergeCompanionDefs() = {
val classDef = mutable.Map[TypeName, TypeDef]()
- for (cdef @ TypeDef(mods, name, _) <- stats)
+ for (cdef @ TypeDef(name, _) <- stats)
if (cdef.isClassDef) classDef(name) = cdef
- for (mdef @ ModuleDef(_, name, _) <- stats)
+ for (mdef @ ModuleDef(name, _) <- stats)
classDef get name.toTypeName match {
case Some(cdef) =>
- val Thicket(vdef :: (mcls @ TypeDef(_, _, impl: Template)) :: Nil) = mdef.attachment(ExpandedTree)
+ val Thicket(vdef :: (mcls @ TypeDef(_, impl: Template)) :: Nil) = mdef.attachment(ExpandedTree)
cdef.attachmentOrElse(ExpandedTree, cdef) match {
- case Thicket(cls :: mval :: TypeDef(_, _, compimpl: Template) :: crest) =>
+ case Thicket(cls :: mval :: TypeDef(_, compimpl: Template) :: crest) =>
val mcls1 = cpy.TypeDef(mcls)(
rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body))
mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: Nil))
@@ -433,7 +433,7 @@ class Namer { typer: Typer =>
protected implicit val ctx: Context = localContext(cls).setMode(ictx.mode &~ Mode.InSuperCall)
- val TypeDef(_, name, impl @ Template(constr, parents, self, body)) = original
+ val TypeDef(name, impl @ Template(constr, parents, self, body)) = original
val (params, rest) = body span {
case td: TypeDef => td.mods is Param
@@ -635,7 +635,7 @@ class Namer { typer: Typer =>
/** The type signature of a DefDef with given symbol */
def defDefSig(ddef: DefDef, sym: Symbol)(implicit ctx: Context) = {
- val DefDef(_, name, tparams, vparamss, _, _) = ddef
+ val DefDef(name, tparams, vparamss, _, _) = ddef
completeParams(tparams)
vparamss foreach completeParams
val isConstructor = name == nme.CONSTRUCTOR
diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala
index 713549840..a2d4ebad8 100644
--- a/src/dotty/tools/dotc/typer/ReTyper.scala
+++ b/src/dotty/tools/dotc/typer/ReTyper.scala
@@ -71,8 +71,9 @@ class ReTyper extends Typer {
override def tryInsertApplyOrImplicit(tree: Tree, pt: ProtoType)(fallBack: (Tree, TyperState) => Tree)(implicit ctx: Context): Tree =
fallBack(tree, ctx.typerState)
- override def addTypedModifiersAnnotations(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers =
- typedModifiers(mods, sym)
+ override def addTypedModifiersAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit =
+ () // was: typedModifiers(Modifiers(sym), sym)
+ // but annotations are not transformed after typer, so no use to check them.
override def ensureConstrCall(cls: ClassSymbol, parents: List[Tree])(implicit ctx: Context): List[Tree] =
parents
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index a5396d445..93a8dff7d 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -312,7 +312,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case templ: untpd.Template =>
import untpd._
val x = tpnme.ANON_CLASS
- val clsDef = TypeDef(Modifiers(Final), x, templ)
+ val clsDef = TypeDef(x, templ).withFlags(Final)
typed(cpy.Block(tree)(clsDef :: Nil, New(Ident(x), Nil)), pt)
case _ =>
val tpt1 = typedType(tree.tpt)
@@ -538,10 +538,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val inferredParams: List[untpd.ValDef] =
for ((param, i) <- params.zipWithIndex) yield
if (!param.tpt.isEmpty) param
- else {
- val paramTpt = untpd.TypeTree(inferredParamType(param, protoFormal(i)))
- cpy.ValDef(param)(param.mods, param.name, paramTpt, param.rhs)
- }
+ else cpy.ValDef(param)(tpt = untpd.TypeTree(inferredParamType(param, protoFormal(i))))
// Define result type of closure as the expected type, thereby pushing
// down any implicit searches. We do this even if the expected type is not fully
@@ -729,7 +726,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val tpt1 = if (tree.tpt.isEmpty) TypeTree(defn.ObjectType) else typedAheadType(tree.tpt)
val refineClsDef = desugar.refinedTypeToClass(tree)
val refineCls = createSymbol(refineClsDef).asClass
- val TypeDef(_, _, Template(_, _, _, refinements1)) = typed(refineClsDef)
+ val TypeDef(_, Template(_, _, _, refinements1)) = typed(refineClsDef)
assert(tree.refinements.length == refinements1.length, s"${tree.refinements} != $refinements1")
def addRefinement(parent: Type, refinement: Tree): Type = {
typr.println(s"adding refinement $refinement")
@@ -785,10 +782,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
assignType(cpy.Alternative(tree)(trees1), trees1)
}
- def addTypedModifiersAnnotations(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers = {
- val mods1 = typedModifiers(mods, sym)
+ def addTypedModifiersAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit = {
+ val mods1 = typedModifiers(untpd.modsDeco(mdef).mods, sym)
for (tree <- mods1.annotations) sym.addAnnotation(Annotation(tree))
- mods1
}
def typedModifiers(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers = track("typedModifiers") {
@@ -802,37 +798,37 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = track("typedValDef") {
- val ValDef(mods, name, tpt, rhs) = vdef
- val mods1 = addTypedModifiersAnnotations(mods, sym)
+ val ValDef(name, tpt, rhs) = vdef
+ addTypedModifiersAnnotations(vdef, sym)
val tpt1 = typedType(tpt)
val rhs1 = rhs match {
case Ident(nme.WILDCARD) => rhs withType tpt1.tpe
case _ => typedExpr(rhs, tpt1.tpe)
}
- assignType(cpy.ValDef(vdef)(mods1, name, tpt1, rhs1), sym)
+ assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
}
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = track("typedDefDef") {
- val DefDef(mods, name, tparams, vparamss, tpt, rhs) = ddef
- val mods1 = addTypedModifiersAnnotations(mods, sym)
+ val DefDef(name, tparams, vparamss, tpt, rhs) = ddef
+ addTypedModifiersAnnotations(ddef, sym)
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1)
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
- assignType(cpy.DefDef(ddef)(mods1, name, tparams1, vparamss1, tpt1, rhs1), sym)
+ assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym)
//todo: make sure dependent method types do not depend on implicits or by-name params
}
def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedTypeDef") {
- val TypeDef(mods, name, rhs) = tdef
- val mods1 = addTypedModifiersAnnotations(mods, sym)
+ val TypeDef(name, rhs) = tdef
+ addTypedModifiersAnnotations(tdef, sym)
val _ = typedType(rhs) // unused, typecheck only to remove from typedTree
- assignType(cpy.TypeDef(tdef)(mods1, name, TypeTree(sym.info), Nil), sym)
+ assignType(cpy.TypeDef(tdef)(name, TypeTree(sym.info), Nil), sym)
}
def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(implicit ctx: Context) = track("typedClassDef") {
- val TypeDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef
+ val TypeDef(name, impl @ Template(constr, parents, self, body)) = cdef
val superCtx = ctx.superCallContext
def typedParent(tree: untpd.Tree): Tree =
if (tree.isType) typedType(tree)(superCtx)
@@ -843,7 +839,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
result
}
- val mods1 = addTypedModifiersAnnotations(mods, cls)
+ addTypedModifiersAnnotations(cdef, cls)
val constr1 = typed(constr).asInstanceOf[DefDef]
val parentsWithClass = ensureFirstIsClass(parents mapconserve typedParent, cdef.pos.toSynthetic)
val parents1 = ensureConstrCall(cls, parentsWithClass)(superCtx)
@@ -854,7 +850,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
.withType(dummy.nonMemberTermRef)
checkVariance(impl1)
- assignType(cpy.TypeDef(cdef)(mods1, name, impl1, Nil), cls)
+ assignType(cpy.TypeDef(cdef)(name, impl1, Nil), cls)
// todo later: check that
// 1. If class is non-abstract, it is instantiatable:
diff --git a/src/dotty/tools/dotc/typer/VarianceChecker.scala b/src/dotty/tools/dotc/typer/VarianceChecker.scala
index e1f50ded9..8fff52170 100644
--- a/src/dotty/tools/dotc/typer/VarianceChecker.scala
+++ b/src/dotty/tools/dotc/typer/VarianceChecker.scala
@@ -128,7 +128,7 @@ class VarianceChecker()(implicit ctx: Context) {
traverseChildren(tree)
case tree: ValDef =>
checkVariance(sym)
- case DefDef(_, _, tparams, vparamss, _, _) =>
+ case DefDef(_, tparams, vparamss, _, _) =>
checkVariance(sym)
tparams foreach traverse
vparamss foreach (_ foreach traverse)