diff options
-rw-r--r-- | src/dotty/tools/dotc/transform/FirstTransform.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 16 | ||||
-rw-r--r-- | tests/pos/i239-packageObj.scala | 11 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/transform/FirstTransform.scala b/src/dotty/tools/dotc/transform/FirstTransform.scala index 42ace148a..3329ac304 100644 --- a/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -124,7 +124,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi normalizeType { val qual = tree.qualifier qual.symbol.moduleClass.denot match { - case pkg: PackageClassDenotation if tree.symbol.maybeOwner.isPackageObject => + case pkg: PackageClassDenotation if !tree.symbol.maybeOwner.is(Package) => cpy.Select(tree)(qual select pkg.packageObj.symbol, tree.name) case _ => tree diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 0f1b81be8..1caa070cc 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -114,15 +114,15 @@ trait TypeAssigner { def ensureAccessible(tpe: Type, superAccess: Boolean, pos: Position)(implicit ctx: Context): Type = { def tryInsertPackageObj(tpe: NamedType, d: Denotation): Type = { - def tryInsert: Type = - if (!(d.symbol.maybeOwner is Package)) { - val symOwner = d.alternatives.head.symbol.owner - if (symOwner.isPackageObject) tpe.derivedSelect(symOwner.thisType) - else tpe - } else tpe + def tryInsert(pkgClass: SymDenotation): Type = pkgClass match { + case pkgCls: PackageClassDenotation if !(d.symbol.maybeOwner is Package) => + tpe.derivedSelect(pkgCls.packageObj.valRef) + case _ => + tpe + } tpe.prefix match { - case pre: ThisType if pre.cls is Package => tryInsert - case pre: TermRef if pre.symbol is Package => tryInsert + case pre: ThisType if pre.cls is Package => tryInsert(pre.cls) + case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass) case _ => tpe } } diff --git a/tests/pos/i239-packageObj.scala b/tests/pos/i239-packageObj.scala new file mode 100644 index 000000000..057bc1eec --- /dev/null +++ b/tests/pos/i239-packageObj.scala @@ -0,0 +1,11 @@ +package p { + class C[A] { def foo: A = ??? } + + object `package` extends C[String] +} + +object test { + + val x: String = p.foo + +} |