diff options
author | Dmitry Petrashko <dark@d-d.me> | 2014-12-18 00:25:45 +0100 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2014-12-18 00:25:45 +0100 |
commit | e0bf1758ac32d69cf97d28f449cc0400755e3914 (patch) | |
tree | 85c09e7626752bcc7938524a44c66cec536c97af /src/dotty | |
parent | a68980c1d322095cdd8d7a2b45b05d901072eeb1 (diff) | |
parent | 0a6461812aa5803726a8607546668f624987b140 (diff) | |
download | dotty-e0bf1758ac32d69cf97d28f449cc0400755e3914.tar.gz dotty-e0bf1758ac32d69cf97d28f449cc0400755e3914.tar.bz2 dotty-e0bf1758ac32d69cf97d28f449cc0400755e3914.zip |
Merge pull request #303 from dotty-staging/fix-packageObjects-members-erasure
Make erasure insert `.package` in TermRefs to members of package object.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/TypeErasure.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeOps.scala | 21 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 17 |
3 files changed, 24 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/TypeErasure.scala b/src/dotty/tools/dotc/TypeErasure.scala index 973e50e8e..a9ae34213 100644 --- a/src/dotty/tools/dotc/TypeErasure.scala +++ b/src/dotty/tools/dotc/TypeErasure.scala @@ -108,7 +108,9 @@ object TypeErasure { def erasedRef(tp: Type)(implicit ctx: Context): Type = tp match { case tp: TermRef => assert(tp.symbol.exists, tp) - TermRef(erasedRef(tp.prefix), tp.symbol.asTerm) + val tp1 = ctx.makePackageObjPrefixExplicit(tp) + if (tp1 ne tp) erasedRef(tp1) + else TermRef(erasedRef(tp.prefix), tp.symbol.asTerm) case tp: ThisType => tp case tp => diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 8190b8cb6..260e2f6d6 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc package core import Contexts._, Types._, Symbols._, Names._, Flags._, Scopes._ -import SymDenotations._ +import SymDenotations._, Denotations.Denotation import config.Printers._ import Decorators._ import StdNames._ @@ -224,6 +224,25 @@ trait TypeOps { this: Context => cls.enter(sym, decls) } + /** If `tpe` is of the form `p.x` where `p` refers to a package + * but `x` is not owned by a package, expand it to + * + * p.package.x + */ + def makePackageObjPrefixExplicit(tpe: NamedType): Type = { + def tryInsert(pkgClass: SymDenotation): Type = pkgClass match { + case pkgCls: PackageClassDenotation if !(tpe.symbol.maybeOwner is Package) => + tpe.derivedSelect(pkgCls.packageObj.valRef) + case _ => + tpe + } + tpe.prefix match { + 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 + } + } + /** If we have member definitions * * type argSym v= from diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 97c959a7a..46aa2e953 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -112,21 +112,6 @@ trait TypeAssigner { * that the package object shows up as the prefix. */ def ensureAccessible(tpe: Type, superAccess: Boolean, pos: Position)(implicit ctx: Context): Type = { - - def tryInsertPackageObj(tpe: NamedType, d: Denotation): Type = { - 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(pre.cls) - case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass) - case _ => tpe - } - } - def test(tpe: Type, firstTry: Boolean): Type = tpe match { case tpe: NamedType => val pre = tpe.prefix @@ -159,7 +144,7 @@ trait TypeAssigner { else if (d.symbol is TypeParamAccessor) // always dereference type param accessors ensureAccessible(d.info.bounds.hi, superAccess, pos) else - tryInsertPackageObj(tpe withDenot d, d) + ctx.makePackageObjPrefixExplicit(tpe withDenot d) case _ => tpe } |