diff options
author | odersky <odersky@gmail.com> | 2015-10-22 14:06:17 +0200 |
---|---|---|
committer | odersky <odersky@gmail.com> | 2015-10-22 14:06:17 +0200 |
commit | b927f66d4b90bc34cc864f596b8d1dc97fdc3ebe (patch) | |
tree | 74dc7951f67672cbf8216ee9142d204e6543a1ad /src/dotty/tools/dotc | |
parent | e92668c024b0c3acf8be0cc229cd7428640a8195 (diff) | |
parent | b482db80c88f575390935b7d1cfbc60e5212f169 (diff) | |
download | dotty-b927f66d4b90bc34cc864f596b8d1dc97fdc3ebe.tar.gz dotty-b927f66d4b90bc34cc864f596b8d1dc97fdc3ebe.tar.bz2 dotty-b927f66d4b90bc34cc864f596b8d1dc97fdc3ebe.zip |
Merge pull request #841 from dotty-staging/fix-#831-object-self
Fix #831 object self
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 41 |
2 files changed, 29 insertions, 19 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index d5ab09930..126af9259 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -736,8 +736,11 @@ object SymDenotations { /** The module implemented by this module class, NoSymbol if not applicable. */ final def sourceModule(implicit ctx: Context): Symbol = myInfo match { - case ClassInfo(_, _, _, _, selfType: TermRef) if this is ModuleClass => - selfType.symbol + case ClassInfo(_, _, _, _, selfType) if this is ModuleClass => + selfType match { + case selfType: TermRef => selfType.symbol + case selfType: Symbol => selfType.info.asInstanceOf[TermRef].symbol + } case info: LazyType => info.sourceModule case _ => diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 52989c1a5..3f732f80c 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), 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 |