Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.compiletime

scala.compiletime

Members list

Type members

Experimental classlikes

traitErased

A marker trait for erased values. vals or parameters whose type extendsErased get an impliciterased modifier.

A marker trait for erased values. vals or parameters whose type extendsErased get an impliciterased modifier.

Attributes

Experimental
true
Source
Erased.scala
Supertypes
classObject
traitMatchable
classAny
Known subtypes
classCanThrow[E]
traitPrecise

Value members

Concrete methods

defbyName[T](x:=>T):T

Assertion that an argument is by-name. Used for nullability checking.

Assertion that an argument is by-name. Used for nullability checking.

Attributes

Source
package.scala
transparent inlinedefcodeOf(arg:Any):String

Returns the string representation of argument code:

Returns the string representation of argument code:

inline def logged(inline p1: Any) =  ("code: " + codeOf(p1), p1)logged(identity("foo"))// above is equivalent to:// ("code: scala.Predef.identity("foo")", identity("foo"))

The formatting of the code is not stable across version of the compiler.

Attributes

Note

onlyinline arguments will be displayed as "code". Other values may display unintutively.

Source
package.scala
transparent inlinedefconstValue[T]:T

Given a constant, singleton typeT, convert it to a value of the same singleton type. For example:assert(constValue[1] == 1).

Given a constant, singleton typeT, convert it to a value of the same singleton type. For example:assert(constValue[1] == 1).

Attributes

Source
package.scala
transparent inlinedefconstValueOpt[T]:Option[T]

Same asconstValue but returns aNone if a constant value cannot be constructed from the provided type. Otherwise returns that value wrapped inSome.

Same asconstValue but returns aNone if a constant value cannot be constructed from the provided type. Otherwise returns that value wrapped inSome.

Attributes

Source
package.scala
inlinedefconstValueTuple[T <:Tuple]:T

Given a tuple type(X1, ..., Xn), returns a tuple value(constValue[X1], ..., constValue[Xn]).

Given a tuple type(X1, ..., Xn), returns a tuple value(constValue[X1], ..., constValue[Xn]).

Attributes

Source
package.scala

Used as the right hand side of a given in a trait, like this

Used as the right hand side of a given in a trait, like this

given T = deferred

This signifies that the given will get a synthesized definition in all classes that implement the enclosing trait and that do not contain an explicit overriding definition of that given.

Attributes

Source
package.scala
deferasedValue[T]:T

Use this method when you have a type, do not have a value for it but want to pattern match on it. For example, given a typeTup <: Tuple, one can pattern-match on it as follows:

Use this method when you have a type, do not have a value for it but want to pattern match on it. For example, given a typeTup <: Tuple, one can pattern-match on it as follows:

type Tupinline def f = {inline erasedValue[Tup] match {  case _: EmptyTuple => ???  case _: (h *: t) => ???}}

This value can only be used in an inline match and the value cannot be used in the branches.

Attributes

Source
package.scala
inlinedeferror(inlinemsg:String):Nothing

The error method is used to produce user-defined compile errors during inline expansion. If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr.

The error method is used to produce user-defined compile errors during inline expansion. If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr.

error("My error message")

or

inline def errorOnThisCode(inline x: Any) =  error("My error of this code: " + codeOf(x))

Attributes

Source
package.scala

Checks at compiletime that the provided values is a constant after inlining and constant folding.

Checks at compiletime that the provided values is a constant after inlining and constant folding.

Usage:

inline def twice(inline n: Int): Int =  requireConst(n) // compile-time assertion that the parameter `n` is a constant  n + ntwice(1)val m: Int = ???twice(m) // error: expected a constant value but found: m

Attributes

Source
package.scala
inlinedefsummonAll[T <:Tuple]:T

Given a tuple T, summons each of its member types and returns them in a Tuple.

Given a tuple T, summons each of its member types and returns them in a Tuple.

Type parameters

T

the tuple containing the types of the values to be summoned

Attributes

Returns

the given values typed as elements of the tuple

Source
package.scala
transparent inlinedefsummonFrom[T](f:Nothing=>T):T

Summons first given matching one of the listed cases. E.g. in

Summons first given matching one of the listed cases. E.g. in

type Atrait Btype Cinline def f = {given B with { }summonFrom {  case given A => 1  case given B => 2  case given C => 3  case _ => 4}}

the returned value would be2.

Attributes

Source
package.scala
transparent inlinedefsummonInline[T]:T

Summon a given value of typeT. Usually, the argument is not passed explicitly. The summoning is delayed until the call has been fully inlined.

Summon a given value of typeT. Usually, the argument is not passed explicitly. The summoning is delayed until the call has been fully inlined.

Type parameters

T

the type of the value to be summoned

Attributes

Returns

the given value typed as the provided type parameter

Source
package.scala

Used as the initializer of a mutable class or object field, like this:

Used as the initializer of a mutable class or object field, like this:

type Tvar x: T = uninitialized

This signifies that the field is not initialized on its own. It is still initialized as part of the bulk initialization of the object it belongs to, which assigns zero values such asnull,0,0.0,false to all object fields.

Attributes

Source
package.scala

Extensions

Extensions

extension[T](x:T)
transparent inlinedefasMatchable: x.type &Matchable

Casts a value to beMatchable. This is needed if the value's type is an unconstrained type parameter and the value is the scrutinee of a match expression. This is normally disallowed since it violates parametricity and allows to uncover implementation details that were intended to be hidden. TheasMatchable escape hatch should be used sparingly. It's usually better to constrain the scrutinee type to beMatchable in the first place.

Casts a value to beMatchable. This is needed if the value's type is an unconstrained type parameter and the value is the scrutinee of a match expression. This is normally disallowed since it violates parametricity and allows to uncover implementation details that were intended to be hidden. TheasMatchable escape hatch should be used sparingly. It's usually better to constrain the scrutinee type to beMatchable in the first place.

Attributes

Source
package.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp