Skip to content

Commit e116c82

Browse files
dwijnandtgodzik
authored andcommitted
Move makePackageObjPrefixExplicit to TypeUtils
1 parent 7fb2a9d commit e116c82

File tree

5 files changed

+37
-34
lines changed

5 files changed

+37
-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
@@ -573,36 +573,6 @@ object TypeOps:
573573
widenMap(tp)
574574
}
575575

576-
/** If `tpe` is of the form `p.x` where `p` refers to a package
577-
* but `x` is not owned by a package, expand it to
578-
*
579-
* p.package.x
580-
*/
581-
def makePackageObjPrefixExplicit(tpe: NamedType)(using Context): Type = {
582-
def tryInsert(pkgClass: SymDenotation): Type = pkgClass match {
583-
case pkg: PackageClassDenotation =>
584-
var sym = tpe.symbol
585-
if !sym.exists && tpe.denot.isOverloaded then
586-
// we know that all alternatives must come from the same package object, since
587-
// otherwise we would get "is already defined" errors. So we can take the first
588-
// symbol we see.
589-
sym = tpe.denot.alternatives.head.symbol
590-
val pobj = pkg.packageObjFor(sym)
591-
if (pobj.exists) tpe.derivedSelect(pobj.termRef)
592-
else tpe
593-
case _ =>
594-
tpe
595-
}
596-
if (tpe.symbol.isRoot)
597-
tpe
598-
else
599-
tpe.prefix match {
600-
case pre: ThisType if pre.cls.is(Package) => tryInsert(pre.cls)
601-
case pre: TermRef if pre.symbol.is(Package) => tryInsert(pre.symbol.moduleClass)
602-
case _ => tpe
603-
}
604-
}
605-
606576
/** An argument bounds violation is a triple consisting of
607577
* - the argument tree
608578
* - a string "upper" or "lower" indicating which bound is violated

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ 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.*
7+
import Names.{Name, TermName}
8+
import Constants.Constant
9+
710
import Names.Name
811
import StdNames.nme
912

@@ -127,6 +130,37 @@ class TypeUtils:
127130
case mt: MethodType => mt.isImplicitMethod || mt.resType.takesImplicitParams
128131
case _ => false
129132

133+
134+
/** If `self` is of the form `p.x` where `p` refers to a package
135+
* but `x` is not owned by a package, expand it to
136+
*
137+
* p.package.x
138+
*/
139+
def makePackageObjPrefixExplicit(using Context): Type =
140+
def tryInsert(tpe: NamedType, pkgClass: SymDenotation): Type = pkgClass match
141+
case pkg: PackageClassDenotation =>
142+
var sym = tpe.symbol
143+
if !sym.exists && tpe.denot.isOverloaded then
144+
// we know that all alternatives must come from the same package object, since
145+
// otherwise we would get "is already defined" errors. So we can take the first
146+
// symbol we see.
147+
sym = tpe.denot.alternatives.head.symbol
148+
val pobj = pkg.packageObjFor(sym)
149+
if pobj.exists then tpe.derivedSelect(pobj.termRef)
150+
else tpe
151+
case _ =>
152+
tpe
153+
self match
154+
case tpe: NamedType =>
155+
if tpe.symbol.isRoot then
156+
tpe
157+
else
158+
tpe.prefix match
159+
case pre: ThisType if pre.cls.is(Package) => tryInsert(tpe, pre.cls)
160+
case pre: TermRef if pre.symbol.is(Package) => tryInsert(tpe, pre.symbol.moduleClass)
161+
case _ => tpe
162+
case tpe => tpe
163+
130164
/** The constructors of this type that are applicable to `argTypes`, without needing
131165
* an implicit conversion. Curried constructors are always excluded.
132166
* @param adaptVarargs if true, allow a constructor with just a varargs argument to

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ class TreeUnpickler(reader: TastyReader,
11891189
val tpe0 = name match
11901190
case name: TypeName => TypeRef(qualType, name, denot)
11911191
case name: TermName => TermRef(qualType, name, denot)
1192-
val tpe = TypeOps.makePackageObjPrefixExplicit(tpe0)
1192+
val tpe = tpe0.makePackageObjPrefixExplicit
11931193
ConstFold.Select(untpd.Select(qual, name).withType(tpe))
11941194

11951195
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
@@ -81,7 +81,7 @@ trait TypeAssigner {
8181
defn.FromJavaObjectType
8282
else tpe match
8383
case tpe: NamedType =>
84-
val tpe1 = TypeOps.makePackageObjPrefixExplicit(tpe)
84+
val tpe1 = tpe.makePackageObjPrefixExplicit
8585
if tpe1 ne tpe then
8686
accessibleType(tpe1, superAccess)
8787
else

0 commit comments

Comments
 (0)