@@ -3,7 +3,7 @@ package dotc
3
3
package core
4
4
5
5
import TypeErasure .ErasedValueType
6
- import Types .* , Contexts .* , Symbols .* , Flags .* , Decorators .*
6
+ import Types .* , Contexts .* , Symbols .* , Flags .* , Decorators .* , SymDenotations . *
7
7
import Names .{Name , TermName }
8
8
import Constants .Constant
9
9
@@ -186,6 +186,36 @@ class TypeUtils:
186
186
case self : Types .ThisType => self.cls == cls
187
187
case _ => false
188
188
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
+
189
219
/** Strip all outer refinements off this type */
190
220
def stripRefinement : Type = self match
191
221
case self : RefinedOrRecType => self.parent.stripRefinement
0 commit comments