Skip to content

Commit 34d11c5

Browse files
committed
Allow enclosing module as qualifying class
1 parent 9b3c727 commit 34d11c5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Scopes._, Contexts._, Constants._, Types._, Symbols._, Names._, Flags._,
88
import ErrorReporting._, Annotations._, Denotations._, SymDenotations._, StdNames._, TypeErasure._
99
import util.Positions._
1010
import config.Printers._
11+
import NameOps._
1112

1213
trait TypeAssigner {
1314
import tpd._
@@ -16,7 +17,11 @@ trait TypeAssigner {
1617
* @param packageOk The qualifier may refer to a package.
1718
*/
1819
def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(implicit ctx: Context): Symbol = {
19-
def qualifies(sym: Symbol) = sym.isClass && (qual.isEmpty || sym.name == qual)
20+
def qualifies(sym: Symbol) =
21+
sym.isClass && (
22+
qual.isEmpty ||
23+
sym.name == qual ||
24+
sym.is(Module) && sym.name.stripModuleClassSuffix == qual)
2025
ctx.outersIterator.map(_.owner).find(qualifies) match {
2126
case Some(c) if packageOK || !(c is Package) =>
2227
c

tests/pos/i324.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class O
2+
object O {
3+
val x: this.type = O.this
4+
}
5+
object O2 {
6+
val x: this.type = O2.this
7+
}

0 commit comments

Comments
 (0)