From 0a6461812aa5803726a8607546668f624987b140 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 17 Dec 2014 17:19:04 +0100 Subject: Simplified and commented makePackageObjPrefixExplicit --- src/dotty/tools/dotc/TypeErasure.scala | 2 +- src/dotty/tools/dotc/core/TypeOps.scala | 9 +++++++-- src/dotty/tools/dotc/typer/TypeAssigner.scala | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dotty/tools/dotc/TypeErasure.scala b/src/dotty/tools/dotc/TypeErasure.scala index 9f9894c57..a9ae34213 100644 --- a/src/dotty/tools/dotc/TypeErasure.scala +++ b/src/dotty/tools/dotc/TypeErasure.scala @@ -108,7 +108,7 @@ object TypeErasure { def erasedRef(tp: Type)(implicit ctx: Context): Type = tp match { case tp: TermRef => assert(tp.symbol.exists, tp) - val tp1 = ctx.makePackageObjPrefixExplicit(tp, tp.symbol) + val tp1 = ctx.makePackageObjPrefixExplicit(tp) if (tp1 ne tp) erasedRef(tp1) else TermRef(erasedRef(tp.prefix), tp.symbol.asTerm) case tp: ThisType => diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 4716d89b7..260e2f6d6 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -224,9 +224,14 @@ trait TypeOps { this: Context => cls.enter(sym, decls) } - def makePackageObjPrefixExplicit(tpe: NamedType, d: Denotation): Type = { + /** 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 !(d.symbol.maybeOwner is Package) => + case pkgCls: PackageClassDenotation if !(tpe.symbol.maybeOwner is Package) => tpe.derivedSelect(pkgCls.packageObj.valRef) case _ => tpe diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index 4394b8557..46aa2e953 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -144,7 +144,7 @@ trait TypeAssigner { else if (d.symbol is TypeParamAccessor) // always dereference type param accessors ensureAccessible(d.info.bounds.hi, superAccess, pos) else - ctx.makePackageObjPrefixExplicit(tpe withDenot d, d) + ctx.makePackageObjPrefixExplicit(tpe withDenot d) case _ => tpe } -- cgit v1.2.3