diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-03 15:26:53 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-03 15:26:53 +0100 |
commit | 62a935f3222eea1d7a08b788b9745c4e99f440f9 (patch) | |
tree | 7ec508b662c7aae66c9c19c63e116e29fd00ac0f /src/dotty/tools/dotc/core/SymDenotations.scala | |
parent | fd5e45bd71c972fddc0f835cdb011beb76a77770 (diff) | |
download | dotty-62a935f3222eea1d7a08b788b9745c4e99f440f9.tar.gz dotty-62a935f3222eea1d7a08b788b9745c4e99f440f9.tar.bz2 dotty-62a935f3222eea1d7a08b788b9745c4e99f440f9.zip |
Drop module class suffix when looking for class with enclosing name.
E.g. in privateWithin.
Diffstat (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index e5f4e8706..e9aeb286a 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -147,6 +147,10 @@ object SymDenotations { myInfo = tp } + /** The name, except if this is a module class, strip the module class suffix */ + def effectiveName = + if (this is ModuleClass) name.stripModuleClassSuffix else name + /** The privateWithin boundary, NoSymbol if no boundary is given. */ final def privateWithin: Symbol = { ensureCompleted(); myPrivateWithin } @@ -216,7 +220,7 @@ object SymDenotations { /** The name with which the denoting symbol was created */ final def originalName = { val d = initial.asSymDenotation - if (d is ExpandedName) d.name.unexpandedName() else d.name + if (d is ExpandedName) d.name.unexpandedName() else d.effectiveName } /** The encoded full path name of this denotation, where outer names and inner names @@ -535,13 +539,13 @@ object SymDenotations { * If this denotation is already a class, return itself */ final def enclosingClass(implicit ctx: Context): Symbol = - if (isClass) symbol else owner.enclosingClass + if (isClass || !exists) symbol else owner.enclosingClass - /** The class containing this denotation which has the given name. + /** The class containing this denotation which has the given effective name. */ final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = { val cls = enclosingClass - if (cls.name == name) cls else cls.owner.enclosingClassNamed(name) + if (cls.effectiveName == name || !cls.exists) cls else cls.owner.enclosingClassNamed(name) } /** The top-level class containing this denotation, @@ -566,7 +570,7 @@ object SymDenotations { */ final def companionModule(implicit ctx: Context): Symbol = if (owner.exists && name != tpnme.ANON_CLASS) // name test to avoid forcing, thereby causing cyclic reference errors - owner.info.decl(name.stripModuleClassSuffix.toTermName) + owner.info.decl(effectiveName.toTermName) .suchThat(sym => (sym is Module) && sym.isCoDefinedWith(symbol)) .symbol else NoSymbol @@ -577,7 +581,7 @@ object SymDenotations { */ final def companionClass(implicit ctx: Context): Symbol = if (owner.exists) - owner.info.decl(name.stripModuleClassSuffix.toTypeName) + owner.info.decl(effectiveName.toTypeName) .suchThat(sym => sym.isClass && sym.isCoDefinedWith(symbol)) .symbol else NoSymbol |