Applications

dotty.tools.dotc.typer.Applications
See theApplications companion object
trait Applications extends Compatibility

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Typer
class ReTyper
class InlineTyper
class Typer
class Checker
class LocalChecker
Show all
Self type

Members list

Type members

Classlikes

class ApplicableToTrees(methRef: TermRef, args: List[Tree], resultType: Type, argMatch: ArgMatch)(using x$5: Context) extends TestApplication[Tree[Type]]

Subclass of Application for applicability tests with type arguments and value argument trees.

Subclass of Application for applicability tests with type arguments and value argument trees.

Attributes

Supertypes
class Object
trait Matchable
class Any
class ApplicableToTypes(methRef: TermRef, args: List[Type], resultType: Type, argMatch: ArgMatch)(using x$5: Context) extends TestApplication[Type]

Subclass of Application for applicability tests with value argument types.

Subclass of Application for applicability tests with value argument types.

Attributes

Supertypes
class Application[Type]
class Object
trait Matchable
class Any
abstract class Application[Arg](methRef: TermRef, funType: Type, args: List[Arg], resultType: Type)(using x$5: Context)

Type parameters

Arg

the type of arguments, could be tpd.Tree, untpd.Tree, or Type

Value parameters

args

the arguments of the application

funType

the type of the function part of the application

methRef

the reference to the method of the application

resultType

the expected result type of the application

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class TestApplication[Arg]
class TypedApply[T]
class ApplyToTyped
Show all
class ApplyToTyped(app: Apply, fun: Tree, methRef: TermRef, args: List[Tree], resultType: Type, applyKind: ApplyKind)(using x$7: Context) extends TypedApply[Type]

Subclass of Application for type checking an Apply node with typed arguments.

Subclass of Application for type checking an Apply node with typed arguments.

Attributes

Supertypes
class TypedApply[Type]
class Object
trait Matchable
class Any
class ApplyToUntyped(app: Apply, fun: Tree, methRef: TermRef, proto: FunProto, resultType: Type)(using x$6: Context) extends TypedApply[Type | Null]

Subclass of Application for type checking an Apply node with untyped arguments.

Subclass of Application for type checking an Apply node with untyped arguments.

Attributes

Supertypes
class TypedApply[Type | Null]
class Application[Tree[Type | Null]]
class Object
trait Matchable
class Any
enum ArgMatch

The degree to which an argument has to match a formal parameter

The degree to which an argument has to match a formal parameter

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
abstract class TestApplication[Arg](methRef: TermRef, funType: Type, args: List[Arg], resultType: Type, argMatch: ArgMatch)(using x$6: Context) extends Application[Arg]

Subclass of Application for the cases where we are interested only in a "can/cannot apply" answer, without needing to construct trees or issue error messages.

Subclass of Application for the cases where we are interested only in a "can/cannot apply" answer, without needing to construct trees or issue error messages.

Attributes

Supertypes
class Application[Arg]
class Object
trait Matchable
class Any
Known subtypes
abstract class TypedApply[T <: Untyped](app: Apply, fun: Tree, methRef: TermRef, args: List[Tree[T]], resultType: Type, val applyKind: ApplyKind)(using x$7: Context) extends Application[Tree[T]]

Subclass of Application for type checking an Apply node, where types of arguments are either known or unknown.

Subclass of Application for type checking an Apply node, where types of arguments are either known or unknown.

Attributes

Supertypes
class Application[Tree[T]]
class Object
trait Matchable
class Any
Known subtypes

Value members

Concrete methods

def ApplyTo(app: Apply, fun: Tree, methRef: TermRef, proto: FunProto, resultType: Type)(using Context): Tree

Typecheck an Apply node with a typed function and possibly-typed arguments coming from proto

Typecheck an Apply node with a typed function and possibly-typed arguments coming from proto

Attributes

def argCtx(app: Tree)(using Context): Context

If app is a this(...) constructor call, the this-call argument context, otherwise the current context.

If app is a this(...) constructor call, the this-call argument context, otherwise the current context.

Attributes

def captureWildcardsCompat(tp: Type, pt: Type)(using Context): Type
def compare(alt1: TermRef, alt2: TermRef)(using Context): Int

Compare two alternatives of an overloaded call or an implicit search.

Compare two alternatives of an overloaded call or an implicit search.

Value parameters

alt1,

alt2 Non-overloaded references indicating the two choices

Attributes

Returns

1 if 1st alternative is preferred over 2nd -1 if 2nd alternative is preferred over 1st 0 if neither alternative is preferred over the other Normal symbols are always preferred over constructor proxies. Otherwise, an alternative A1 is preferred over an alternative A2 if it wins in a tournament that awards one point for each of the following:

  • A1's owner derives from A2's owner.
  • A1's type is more specific than A2's type. If that tournament yields a draw, a tiebreak is applied where an alternative that takes more implicit parameters wins over one that takes fewer.
def compareOwner(sym1: Symbol, sym2: Symbol)(using Context): Int

Compare owner inheritance level.

Compare owner inheritance level.

Value parameters

sym1

The first owner

sym2

The second owner

Attributes

Returns

1 if sym1 properly derives from sym2 -1 if sym2 properly derives from sym1 0 otherwise Module classes also inherit the relationship from their companions. This means, if no direct derivation exists between sym1 and sym2 also perform the following tests:

  • If both sym1 and sym1 are module classes that have companion classes, and sym2 does not inherit implicit members from a base class (#), compare the companion classes.
  • If sym1 is a module class with a companion, and sym2 is a normal class or trait, compare the companion with sym2. Condition (#) is necessary to make compareOwner(_, _) > 0 a transitive relation. For instance: class A extends B object A { given a ... } class B object B extends C { given b ... } class C { given c } Then without (#), and taking A$ for the module class of A, compareOwner(A$, B$) = 1 and compareOwner(B$, C) == 1, but compareOwner(A$, C) == 0. Violating transitivity in this way is bad, since it makes implicit search outcomes compilation order dependent. E.g. if we compare b with c first, we pick b. Then, if we compare a and b, we pick a as solution of the search. But if we start with comparing a with c, we get an ambiguity. With the added condition (#), compareOwner(A$, B$) == 0. This means we get an ambiguity between a and b in all cases.

Rewrite new Array[T](....) if T is an unbounded generic to calls to newGenericArray. It is performed during typer as creation of generic arrays needs a classTag. we rely on implicit search to find one.

Rewrite new Array[T](....) if T is an unbounded generic to calls to newGenericArray. It is performed during typer as creation of generic arrays needs a classTag. we rely on implicit search to find one.

Attributes

def extMethodApply(methodRef: Tree, receiver: Tree, pt: Type)(using Context): Tree

The typed application

The typed application

( ) or

where comes from pt if it is a (possibly ignored) PolyProto.

Attributes

def harmonic[T](harmonize: (List[T]) => List[T], pt: Type)(op: => List[T])(using Context): List[T]

Apply a transformation harmonize on the results of operation op, unless the expected type pt is fully defined. If the result is different (wrt eq) from the original results of op, revert back to the constraint in force before computing op. This reset is needed because otherwise the original results might have added constraints to type parameters which are no longer implied after harmonization. No essential constraints are lost by this because the result of harmonization will be compared again with the expected type. Test cases where this matters are in neg/harmomize.scala and run/weak-conformance.scala.

Apply a transformation harmonize on the results of operation op, unless the expected type pt is fully defined. If the result is different (wrt eq) from the original results of op, revert back to the constraint in force before computing op. This reset is needed because otherwise the original results might have added constraints to type parameters which are no longer implied after harmonization. No essential constraints are lost by this because the result of harmonization will be compared again with the expected type. Test cases where this matters are in neg/harmomize.scala and run/weak-conformance.scala.

Note: this assumes that the internal typing of the arguments using op does not leave any constraints, so the only info that is reset is the relationship between the argument's types and the expected type. I am not sure this will always be the case. If that property does not hold, we risk forgetting constraints which could lead to unsoundness.

Attributes

def harmonize(trees: List[Tree])(using Context): List[Tree]

If trees all have numeric value types, and they do not have all the same type, pick a common numeric supertype and try to convert all constant Int literals to this type. If the resulting trees all have the same type, return them instead of the original ones.

If trees all have numeric value types, and they do not have all the same type, pick a common numeric supertype and try to convert all constant Int literals to this type. If the resulting trees all have the same type, return them instead of the original ones.

Attributes

def hasExtensionMethodNamed(tp: Type, xname: TermName, argType: Type, resultType: Type)(using Context): Boolean

Does tp have an extension method named xname with this-argument argType and result matching resultType?

Does tp have an extension method named xname with this-argument argType and result matching resultType?

Attributes

def isApplicableExtensionMethod(methodRef: TermRef, receiverType: Type)(using Context): Boolean
def isApplicableMethodRef(methRef: TermRef, args: List[Tree], resultType: Type, keepConstraint: Boolean, argMatch: ArgMatch)(using Context): Boolean

Is given method reference applicable to argument trees args?

Is given method reference applicable to argument trees args?

Value parameters

resultType

The expected result type of the application

Attributes

def isApplicableMethodRef(methRef: TermRef, args: List[Type], resultType: Type, argMatch: ArgMatch)(using Context): Boolean

Is given method reference applicable to argument types args?

Is given method reference applicable to argument types args?

Value parameters

resultType

The expected result type of the application

Attributes

def isApplicableType(tp: Type, args: List[Tree], resultType: Type, keepConstraint: Boolean)(using Context): Boolean

Is given type applicable to argument trees args, possibly after inserting an apply?

Is given type applicable to argument trees args, possibly after inserting an apply?

Value parameters

resultType

The expected result type of the application

Attributes

def isApplicableType(tp: Type, args: List[Type], resultType: Type)(using Context): Boolean

Is given type applicable to argument types args, possibly after inserting an apply?

Is given type applicable to argument types args, possibly after inserting an apply?

Value parameters

resultType

The expected result type of the application

Attributes

def isUnary(tp: Type)(using Context): Boolean

Is tp a unary function type or an overloaded type with with only unary function types as alternatives?

Is tp a unary function type or an overloaded type with with only unary function types as alternatives?

Attributes

def needsTupledDual(funType: Type, pt: FunProto)(using Context): Boolean

Should we tuple or untuple the argument before application? If auto-tupling is enabled then

Should we tuple or untuple the argument before application? If auto-tupling is enabled then

  • we tuple n-ary arguments where n > 0 if the function consists only of unary alternatives
  • we untuple tuple arguments of infix operations if the function does not consist only of unary alternatives.

Attributes

def resolveMapped(alts: List[TermRef], f: TermRef => Type, pt: Type)(using Context): List[TermRef]

Resolve overloading by mapping to a different problem where each alternative's type is mapped with f, alternatives with non-existing types are dropped, and the expected type is pt. Map the results back to the original alternatives.

Resolve overloading by mapping to a different problem where each alternative's type is mapped with f, alternatives with non-existing types are dropped, and the expected type is pt. Map the results back to the original alternatives.

Attributes

def resolveOverloaded(alts: List[TermRef], pt: Type)(using Context): List[TermRef]

Resolve overloaded alternative alts, given expected type pt. Two trials: First, without implicits or SAM conversions enabled. Then, if the first finds no eligible candidates, with implicits and SAM conversions enabled.

Resolve overloaded alternative alts, given expected type pt. Two trials: First, without implicits or SAM conversions enabled. Then, if the first finds no eligible candidates, with implicits and SAM conversions enabled.

Attributes

def saysNotFound(state: TyperState, memberName: Name)(using Context): Boolean

Does state contain a "NotAMember" or "MissingIdent" message as first pending error message? That message would be $memberName is not a member of ... or Not found: $memberName. If memberName is empty, any name will do.

Does state contain a "NotAMember" or "MissingIdent" message as first pending error message? That message would be $memberName is not a member of ... or Not found: $memberName. If memberName is empty, any name will do.

Attributes

def stripImplicit(tp: Type, wildcardOnly: Boolean)(using Context): Type

Drop any leading implicit parameter sections

Drop any leading implicit parameter sections

Attributes

def stripInferrable(tp: Type)(using Context): Type

Drop any leading type or implicit parameter sections

Drop any leading type or implicit parameter sections

Attributes

def trimParamss(t: Type, paramss: List[List[Symbol]])(using Context): (List[List[Symbol]], Int)

The largest suffix of paramss that has the same first parameter name as t, plus the number of term parameters in paramss that come before that suffix.

The largest suffix of paramss that has the same first parameter name as t, plus the number of term parameters in paramss that come before that suffix.

Attributes

def tryApplyingExtensionMethod(methodRef: TermRef, receiver: Tree)(using Context): Option[Tree]

Assuming methodRef is a reference to an extension method defined e.g. as

Assuming methodRef is a reference to an extension method defined e.g. as

extension [T1, T2](using A)(using B, C)(receiver: R)(using D) def foo[T3](using E)(f: F): G = ???

return the tree representing methodRef partially applied to the receiver and all the implicit parameters preceding it (A, B, C) with the type parameters of the extension (T1, T2) inferred. None is returned if the implicit search fails for any of the leading implicit parameters or if the receiver has a wrong type (note that in general the type of the receiver might depend on the exact types of the found instances of the proceeding implicits). No implicit search is tried for implicits following the receiver or for parameters of the def (D, E).

Attributes

def typedApply(tree: Apply, pt: Type)(using Context): Tree

Typecheck application. Result could be an Apply node, or, if application is an operator assignment, also an Assign or Block node.

Typecheck application. Result could be an Apply node, or, if application is an operator assignment, also an Assign or Block node.

Attributes

def typedNamedArgs(args: List[Tree])(using Context): List[NamedArg]
def typedTypeApply(tree: TypeApply, pt: Type)(using Context): Tree
def typedUnApply(tree: Apply, selType: Type)(using Context): Tree
def typedUnApply(tree: UnApply, selType: Type)(using Context): UnApply

A typed unapply hook, can be overridden by re any-typers between frontend and pattern matcher.

A typed unapply hook, can be overridden by re any-typers between frontend and pattern matcher.

Attributes

def widenEnumCase(tree: Tree, pt: Type)(using Context): Tree

If tree is a complete application of a compiler-generated apply or copy method of an enum case, widen its type to the underlying type by means of a type ascription, as long as the widened type is still compatible with the expected type. The underlying type is the intersection of all class parents of the original type.

If tree is a complete application of a compiler-generated apply or copy method of an enum case, widen its type to the underlying type by means of a type ascription, as long as the widened type is still compatible with the expected type. The underlying type is the intersection of all class parents of the original type.

Attributes

Inherited methods

def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean

Constrain result with special case if meth is a transparent inlineable method in an inlineable context. In that case, we should always succeed and not constrain type parameters in the expected type, because the actual return type can be a subtype of the currently known return type. However, we should constrain parameters of the declared return type. This distinction is achieved by replacing expected type parameters with wildcards.

Constrain result with special case if meth is a transparent inlineable method in an inlineable context. In that case, we should always succeed and not constrain type parameters in the expected type, because the actual return type can be a subtype of the currently known return type. However, we should constrain parameters of the declared return type. This distinction is achieved by replacing expected type parameters with wildcards.

Attributes

Inherited from:
Compatibility
def constrainResult(mt: Type, pt: Type)(using Context): Boolean

Check that the result type of the current method fits the given expected result type.

Check that the result type of the current method fits the given expected result type.

Attributes

Inherited from:
Compatibility
def isCompatible(tp: Type, pt: Type)(using Context): Boolean

A type tp is compatible with a type pt if one of the following holds:

A type tp is compatible with a type pt if one of the following holds:

  1. tp is a subtype of pt
  2. pt is by name parameter type, and tp is compatible with its underlying type
  3. there is an implicit conversion from tp to pt.
  4. tp is a numeric subtype of pt (this case applies even if implicit conversions are disabled) If pt is a by-name type, we compare against the underlying type instead.

Attributes

Inherited from:
Compatibility

Like normalize and then isCompatible, but using a subtype comparison with necessary eithers that does not unnecessarily truncate the constraint space, returning false instead.

Like normalize and then isCompatible, but using a subtype comparison with necessary eithers that does not unnecessarily truncate the constraint space, returning false instead.

Attributes

Inherited from:
Compatibility
def normalizedCompatible(tp: Type, pt: Type, keepConstraint: Boolean)(using Context): Boolean

Test compatibility after normalization. If keepConstraint is false, the current constraint set will not be modified by this call.

Test compatibility after normalization. If keepConstraint is false, the current constraint set will not be modified by this call.

Attributes

Inherited from:
Compatibility
def viewExists(tp: Type, pt: Type)(using Context): Boolean

Is there an implicit conversion from tp to pt?

Is there an implicit conversion from tp to pt?

Attributes

Inherited from:
Compatibility