aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-29 14:44:49 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-29 14:44:49 +0200
commit28f8102d1b4e8c8fd2d2f1838b49e70844245a5f (patch)
tree066c90ced4254e96eb90cd13bc8b506b7ddc7e2e /src/dotty/tools/dotc/typer/Namer.scala
parente47b840e7b3d4f77a32fe823dd2eaf703aff36b3 (diff)
downloaddotty-28f8102d1b4e8c8fd2d2f1838b49e70844245a5f.tar.gz
dotty-28f8102d1b4e8c8fd2d2f1838b49e70844245a5f.tar.bz2
dotty-28f8102d1b4e8c8fd2d2f1838b49e70844245a5f.zip
Buf fixing of namer/typer interface.
Make sure that only expanded trees are passed to functions that require expanded trees.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 887970b67..97cc37cc3 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -62,7 +62,9 @@ class Namer { typer: Typer =>
/** A partial map from unexpanded member and pattern defs and to their expansions.
* Populated during enterSyms, emptied during typer.
*/
- lazy val expandedTree = new mutable.HashMap[DefTree, Tree]
+ lazy val expandedTree = new mutable.HashMap[DefTree, Tree] {
+ override def default(tree: DefTree) = tree
+ }
/** A map from expanded MemberDef, PatDef or Import trees to their symbols.
* Populated during enterSyms, emptied at the point a typed tree
@@ -91,9 +93,12 @@ class Namer { typer: Typer =>
val scope = newScope
/** The symbol of the given expanded tree. */
- def symbolOfTree(tree: Tree)(implicit ctx: Context): Symbol = typedTree get tree match {
- case Some(tree1) => tree1.denot.symbol
- case _ => symOfTree(tree)
+ def symbolOfTree(tree: Tree)(implicit ctx: Context): Symbol = {
+ val xtree = expanded(tree)
+ typedTree get xtree match {
+ case Some(ttree) => ttree.denot.symbol
+ case _ => symOfTree(xtree)
+ }
}
/** The enclosing class with given name; error if none exists */
@@ -122,7 +127,7 @@ class Namer { typer: Typer =>
def privateWithinClass(mods: Modifiers) =
enclosingClassNamed(mods.privateWithin, mods.pos)
- def record(tree: Tree, sym: Symbol): Symbol = {
+ def record(sym: Symbol): Symbol = {
symOfTree(tree) = sym
sym
}
@@ -141,17 +146,17 @@ class Namer { typer: Typer =>
println(i"creating symbol for $tree")
tree match {
case tree: TypeDef if tree.isClassDef =>
- record(tree, ctx.newClassSymbol(
+ record(ctx.newClassSymbol(
ctx.owner, tree.name, tree.mods.flags,
adjustIfModule(new Completer(tree) withDecls newScope, tree),
privateWithinClass(tree.mods), tree.pos, ctx.source.file))
case tree: MemberDef =>
- record(tree, ctx.newSymbol(
+ record(ctx.newSymbol(
ctx.owner, tree.name, tree.mods.flags,
adjustIfModule(new Completer(tree), tree),
privateWithinClass(tree.mods), tree.pos))
- case imp: Import =>
- record(imp, ctx.newSymbol(
+ case tree: Import =>
+ record(ctx.newSymbol(
ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos))
case _ =>
NoSymbol
@@ -193,6 +198,12 @@ class Namer { typer: Typer =>
expanded
}
+ /** The expanded version of this tree, or tree itself if not expanded */
+ def expanded(tree: Tree)(implicit ctx: Context): Tree = tree match {
+ case ddef: DefTree => expandedTree(ddef)
+ case _ => tree
+ }
+
/** A new context that summarizes an import statement */
def importContext(sym: Symbol, selectors: List[Tree])(implicit ctx: Context) =
ctx.fresh.withImportInfo(new ImportInfo(sym, selectors))
@@ -328,8 +339,8 @@ class Namer { typer: Typer =>
}
/** Typecheck tree during completion, and remember result in typedtree map */
- private def typedAheadImpl(tree: Tree, pt: Type)(implicit ctx: Context): tpd.Tree =
- typedTree.getOrElseUpdate(tree, typer.typedExpanded(tree, pt))
+ private def typedAheadImpl(tree: Tree, pt: Type)(implicit ctx: Context): tpd.Tree =
+ typedTree.getOrElseUpdate(expanded(tree), typer.typedUnadapted(tree, pt))
def typedAheadType(tree: Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree =
typedAheadImpl(tree, pt)(ctx retractMode Mode.PatternOrType addMode Mode.Type)