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

dotty.tools.package.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
package dotty

package object tools {

  val ListOfNil: List[Nil.type] = Nil :: Nil

  /** Throws an `UnsupportedOperationException` with the given method name. */
  def unsupported(methodName: String): Nothing =
    throw new UnsupportedOperationException(methodName)

  /** Forward-ported from the explicit-nulls branch. */
  extension [T](x: T | Null)
    /** Should be used when we know from the context that `x` is not null.
     *  Flow-typing under explicit nulls will automatically insert many necessary
     *  occurrences of uncheckedNN.
     */
    transparent inline def uncheckedNN: T = x.asInstanceOf[T]

    inline def toOption: Option[T] =
      if x == null then None else Some(x.asInstanceOf[T])
  end extension

  /** Nullable eq and ne. */
  extension [T <: AnyRef](x: T | Null)
    inline def eqn (y: T | Null) =
      x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]

    inline def nen(y: T | Null): Boolean = !eqn(y)

  object resultWrapper {
    opaque type WrappedResult[T] = T
    private[tools] def unwrap[T](x: WrappedResult[T]): T = x
    private[tools] def wrap[T](x: T): WrappedResult[T] = x
  }
  type WrappedResult[T] = resultWrapper.WrappedResult[T]
  def WrappedResult[T](x: T) = resultWrapper.wrap(x)
  def result[T](using x: WrappedResult[T]): T = resultWrapper.unwrap(x)

  def unreachable(x: Any = "<< this case was declared unreachable >>"): Nothing =
    throw new MatchError(x)

  transparent inline def assertShort(inline assertion: Boolean, inline message: Any = null): Unit =
    if !assertion then
      val msg = message
      val e = if msg == null then AssertionError() else AssertionError("assertion failed: " + msg)
      e.setStackTrace(Array())
      throw e

  // Ensure this object is already classloaded, since it's only actually used
  // when handling stack overflows and every operation (including class loading)
  // risks failing.
  dotty.tools.dotc.core.handleRecursive
 }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy