aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-10-22 10:11:46 +0200
committerMartin Odersky <odersky@gmail.com>2015-10-22 13:28:47 +0200
commit9421e61051bf56329045250132e184065810ea13 (patch)
treeb4798d334dffb8862bd9f084bbc92daa888001a7 /src/dotty/tools/dotc/typer/Namer.scala
parent6b7c51c5c4f02b7713f5f44c4de4a287cdd329c6 (diff)
downloaddotty-9421e61051bf56329045250132e184065810ea13.tar.gz
dotty-9421e61051bf56329045250132e184065810ea13.tar.bz2
dotty-9421e61051bf56329045250132e184065810ea13.zip
Fix #831
Need to create a self symbols for modules with explicit self type, but need to take care it is already typed, or sourceModule risks running into CyclicReferences.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 52989c1a5..9143ff977 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -216,6 +216,17 @@ class Namer { typer: Typer =>
}
}
+ /** Record `sym` as the symbol defined by `tree` */
+ def recordSym(sym: Symbol, tree: Tree)(implicit ctx: Context): Symbol = {
+ val refs = tree.attachmentOrElse(References, Nil)
+ if (refs.nonEmpty) {
+ tree.removeAttachment(References)
+ refs foreach (_.pushAttachment(OriginalSymbol, sym))
+ }
+ tree.pushAttachment(SymOfTree, sym)
+ sym
+ }
+
/** If this tree is a member def or an import, create a symbol of it
* and store in symOfTree map.
*/
@@ -224,16 +235,6 @@ class Namer { typer: Typer =>
def privateWithinClass(mods: Modifiers) =
enclosingClassNamed(mods.privateWithin, mods.pos)
- def record(sym: Symbol): Symbol = {
- val refs = tree.attachmentOrElse(References, Nil)
- if (refs.nonEmpty) {
- tree.removeAttachment(References)
- refs foreach (_.pushAttachment(OriginalSymbol, sym))
- }
- tree.pushAttachment(SymOfTree, sym)
- sym
- }
-
def checkFlags(flags: FlagSet) =
if (flags.isEmpty) flags
else {
@@ -274,10 +275,10 @@ class Namer { typer: Typer =>
case tree: TypeDef if tree.isClassDef =>
val name = checkNoConflict(tree.name.encode).asTypeName
val flags = checkFlags(tree.mods.flags &~ Implicit)
- val cls = record(ctx.newClassSymbol(
+ val cls = recordSym(ctx.newClassSymbol(
ctx.owner, name, flags | inSuperCall,
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
- privateWithinClass(tree.mods), tree.pos, ctx.source.file))
+ privateWithinClass(tree.mods), tree.pos, ctx.source.file)SyS, tree)
cls.completer.asInstanceOf[ClassCompleter].init()
cls
case tree: MemberDef =>
@@ -304,13 +305,13 @@ class Namer { typer: Typer =>
// have no implementation.
val cctx = if (tree.name == nme.CONSTRUCTOR && !(tree.mods is JavaDefined)) ctx.outer else ctx
- record(ctx.newSymbol(
+ recordSym(ctx.newSymbol(
ctx.owner, name, flags | deferred | method | higherKinded | inSuperCall1,
adjustIfModule(new Completer(tree)(cctx), tree),
- privateWithinClass(tree.mods), tree.pos))
+ privateWithinClass(tree.mods), tree.pos), tree)
case tree: Import =>
- record(ctx.newSymbol(
- ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos))
+ recordSym(ctx.newSymbol(
+ ctx.owner, nme.IMPORT, Synthetic, new Completer(tree), NoSymbol, tree.pos), tree)
case _ =>
NoSymbol
}
@@ -579,7 +580,13 @@ class Namer { typer: Typer =>
val selfInfo =
if (self.isEmpty) NoType
- else if (cls is Module) cls.owner.thisType select sourceModule
+ else if (cls.is(Module)) {
+ val moduleType = cls.owner.thisType select sourceModule
+ if (self.name == nme.WILDCARD) moduleType
+ else recordSym(
+ ctx.newSymbol(cls, self.name, self.mods.flags, moduleType, coord = self.pos),
+ self)
+ }
else createSymbol(self)
// pre-set info, so that parent types can refer to type params