dotty.tools.dotc.transform.ElimPackagePrefixes.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala3-compiler_3 Show documentation
Show all versions of scala3-compiler_3 Show documentation
scala3-compiler-bootstrapped
package dotty.tools.dotc
package transform
import core.*
import Decorators.*, Flags.*, Types.*, Contexts.*, Symbols.*
import ast.tpd.*
import Flags.*
import MegaPhase.MiniPhase
/** Eliminates syntactic references to package terms as prefixes of classes, so that there's no chance
* they accidentally end up in the backend.
*/
class ElimPackagePrefixes extends MiniPhase {
override def phaseName: String = ElimPackagePrefixes.name
override def description: String = ElimPackagePrefixes.description
override def transformSelect(tree: Select)(using Context): Tree =
if (isPackageClassRef(tree)) Ident(tree.tpe.asInstanceOf[TypeRef]) else tree
override def checkPostCondition(tree: Tree)(using Context): Unit = tree match {
case tree: Select =>
assert(!isPackageClassRef(tree), i"Unexpected reference to package in $tree")
case _ =>
}
/** Is the given tree a reference to a type in a package? */
private def isPackageClassRef(tree: Select)(using Context): Boolean = tree.tpe match {
case TypeRef(prefix, _) => prefix.termSymbol.is(Package)
case _ => false
}
}
object ElimPackagePrefixes:
val name: String = "elimPackagePrefixes"
val description: String = "eliminate references to package prefixes in Select nodes"
© 2015 - 2025 Weber Informatics LLC | Privacy Policy