Skip to content

Commit f9145d7

Browse files
committed
Move makePackageObjPrefixExplicit to TypeUtils
1 parent 7f141a9 commit f9145d7

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package core
55
import Symbols.*, Types.*, Contexts.*, Flags.*, Names.*, StdNames.*, Phases.*
66
import Flags.JavaDefined
77
import Uniques.unique
8-
import TypeOps.makePackageObjPrefixExplicit
98
import backend.sjs.JSDefinitions
109
import transform.ExplicitOuter.*
1110
import transform.ValueClasses.*

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -560,36 +560,6 @@ object TypeOps:
560560
widenMap(tp)
561561
}
562562

563-
/** If `tpe` is of the form `p.x` where `p` refers to a package
564-
* but `x` is not owned by a package, expand it to
565-
*
566-
* p.package.x
567-
*/
568-
def makePackageObjPrefixExplicit(tpe: NamedType)(using Context): Type = {
569-
def tryInsert(pkgClass: SymDenotation): Type = pkgClass match {
570-
case pkg: PackageClassDenotation =>
571-
var sym = tpe.symbol
572-
if !sym.exists && tpe.denot.isOverloaded then
573-
// we know that all alternatives must come from the same package object, since
574-
// otherwise we would get "is already defined" errors. So we can take the first
575-
// symbol we see.
576-
sym = tpe.denot.alternatives.head.symbol
577-
val pobj = pkg.packageObjFor(sym)
578-
if (pobj.exists) tpe.derivedSelect(pobj.termRef)
579-
else tpe
580-
case _ =>
581-
tpe
582-
}
583-
if (tpe.symbol.isRoot)
584-
tpe
585-
else
586-
tpe.prefix match {
587-
case pre: ThisType if pre.cls.is(Package) => tryInsert(pre.cls)
588-
case pre: TermRef if pre.symbol.is(Package) => tryInsert(pre.symbol.moduleClass)
589-
case _ => tpe
590-
}
591-
}
592-
593563
/** An argument bounds violation is a triple consisting of
594564
* - the argument tree
595565
* - a string "upper" or "lower" indicating which bound is violated

compiler/src/dotty/tools/dotc/core/TypeUtils.scala

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package core
44

55
import TypeErasure.ErasedValueType
6-
import Types.*, Contexts.*, Symbols.*, Flags.*, Decorators.*
6+
import Types.*, Contexts.*, Symbols.*, Flags.*, Decorators.*, SymDenotations.*
77
import Names.{Name, TermName}
88
import Constants.Constant
99

@@ -186,6 +186,36 @@ class TypeUtils:
186186
case self: Types.ThisType => self.cls == cls
187187
case _ => false
188188

189+
/** If `self` is of the form `p.x` where `p` refers to a package
190+
* but `x` is not owned by a package, expand it to
191+
*
192+
* p.package.x
193+
*/
194+
def makePackageObjPrefixExplicit(using Context): Type =
195+
def tryInsert(tpe: NamedType, pkgClass: SymDenotation): Type = pkgClass match
196+
case pkg: PackageClassDenotation =>
197+
var sym = tpe.symbol
198+
if !sym.exists && tpe.denot.isOverloaded then
199+
// we know that all alternatives must come from the same package object, since
200+
// otherwise we would get "is already defined" errors. So we can take the first
201+
// symbol we see.
202+
sym = tpe.denot.alternatives.head.symbol
203+
val pobj = pkg.packageObjFor(sym)
204+
if pobj.exists then tpe.derivedSelect(pobj.termRef)
205+
else tpe
206+
case _ =>
207+
tpe
208+
self match
209+
case tpe: NamedType =>
210+
if tpe.symbol.isRoot then
211+
tpe
212+
else
213+
tpe.prefix match
214+
case pre: ThisType if pre.cls.is(Package) => tryInsert(tpe, pre.cls)
215+
case pre: TermRef if pre.symbol.is(Package) => tryInsert(tpe, pre.symbol.moduleClass)
216+
case _ => tpe
217+
case tpe => tpe
218+
189219
/** Strip all outer refinements off this type */
190220
def stripRefinement: Type = self match
191221
case self: RefinedOrRecType => self.parent.stripRefinement

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ class TreeUnpickler(reader: TastyReader,
12721272
val tpe0 = name match
12731273
case name: TypeName => TypeRef(qualType, name, denot)
12741274
case name: TermName => TermRef(qualType, name, denot)
1275-
val tpe = TypeOps.makePackageObjPrefixExplicit(tpe0)
1275+
val tpe = tpe0.makePackageObjPrefixExplicit
12761276
ConstFold.Select(untpd.Select(qual, name).withType(tpe))
12771277

12781278
def completeSelect(name: Name, sig: Signature, target: Name): Select =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ trait TypeAssigner {
8585
defn.FromJavaObjectType
8686
else tpe match
8787
case tpe: NamedType =>
88-
val tpe1 = TypeOps.makePackageObjPrefixExplicit(tpe)
88+
val tpe1 = tpe.makePackageObjPrefixExplicit
8989
if tpe1 ne tpe then
9090
accessibleType(tpe1, superAccess)
9191
else

0 commit comments

Comments
 (0)