All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dotc.transform.ElimPackagePrefixes.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
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