Dotty Documentation

0.10.0-bin-SNAPSHOT

class Typer
extends Namer with TypeAssigner with Applications with Implicits with Inferencing with Dynamic with Checking with Docstrings

[-] Constructors

Typer ( )

[-] Members

[+] private var foundUnderScala2 : Type

Temporary data item for single call to typed ident: This symbol would be found under Scala2 mode, but is not in dotty (because dotty conforms to spec section 2 wrt to package member resolution but scalac doe not).

[+] private var unimported : Set [ Symbol ]

A temporary data item valid for a single typed ident: The set of all root import symbols that have been encountered as a qualifier of an import so far. Note: It would be more proper to move importedFromRoot into typedIdent. We should check that this has no performance degradation, however.

[+] def adapt ( tree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : Tree

Perform the following adaptations of expression, pattern or type tree wrt to given prototype pt: (1) Resolve overloading (2) Apply parameterless functions (3) Apply polymorphic types to fresh instances of their type parameters and store these instances in context.undetparams, unless followed by explicit type application. (4) Do the following to unapplied methods used as values: (4.1) If the method has only implicit parameters pass implicit arguments (4.2) otherwise, if pt is a function type and method is not a constructor, convert to function by eta-expansion, (4.3) otherwise, if the method is nullary with a result type compatible to pt and it is not a constructor, apply it to () otherwise issue an error (5) Convert constructors in a pattern as follows: (5.1) If constructor refers to a case class factory, set tree's type to the unique instance of its primary constructor that is a subtype of the expected type. (5.2) If constructor refers to an extractor, convert to application of unapply or unapplySeq method.

(6) Convert all other types to TypeTree nodes. (7) When in TYPEmode but not FUNmode or HKmode, check that types are fully parameterized (7.1) In HKmode, higher-kinded types are allowed, but they must have the expected kind-arity (8) When in both EXPRmode and FUNmode, add apply method calls to values of object type. (9) If there are undetermined type variables and not POLYmode, infer expression instance Then, if tree's type is not a subtype of expected type, try the following adaptations: (10) If the expected type is Byte, Short or Char, and the expression is an integer fitting in the range of that type, convert it to that type. (11) Widen numeric literals to their expected type, if necessary (12) When in mode EXPRmode, convert E to { E; () } if expected type is scala.Unit. (13) When in mode EXPRmode, apply AnnotationChecker conversion if expected type is annotated. (14) When in mode EXPRmode, apply a view If all this fails, error Parameters as for typedUnadapted.

[+] final def adapt ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] private def adapt1 ( tree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : Tree
[+] protected def addAccessorDefs ( cls: Symbol , body: List [ Tree ] ) ( implicit ctx: Context ) : List [ Tree ]
[+] def annotContext ( mdef: Tree , sym: Symbol ) ( implicit ctx: Context ) : Context

The context to be used for an annotation of mdef. This should be the context enclosing mdef, or if mdef defines a parameter the context enclosing the owner of mdef. Furthermore, we need to evaluate annotation arguments in an expression context, since classes defined in a such arguments should not be entered into the enclosing class.

[+] protected def checkEqualityEvidence ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Unit

Check that tree == x: pt is typeable. Used when checking a pattern against a selector of type pt. This implementation accounts for user-defined definitions of ==.

Overwritten to no-op in ReTyper.

[+] private def checkStableIdentPattern ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : tree.type

Check that a stable identifier pattern is indeed stable (SLS 8.1.5)

[+] def checkVariance ( tree: Tree ) ( implicit ctx: Context ) : Unit

Overridden in retyper

[+] def completeAnnotations ( mdef: MemberDef , sym: Symbol ) ( implicit ctx: Context ) : Unit
[+] private def decomposeProtoFunction ( pt: Type , defaultArity: Int ) ( implicit ctx: Context ) : ( List [ Type ], Tree )

Decompose function prototype into a list of parameter prototypes and a result prototype tree, using WildcardTypes where a type is not known. For the result type we do this even if the expected type is not fully defined, which is a bit of a hack. But it's needed to make the following work (see typers.scala and printers/PlainPrinter.scala for examples).

def double(x: Char): String = s"$x$x" "abc" flatMap double

[+] def ensureConstrCall ( cls: ClassSymbol , parents: List [ Tree ] ) ( implicit ctx: Context ) : List [ Tree ]

If this is a real class, make sure its first parent is a constructor call. Cannot simply use a type. Overridden in ReTyper.

[+] def ensureFirstIsClass ( parents: List [ Type ] , pos: Position ) ( implicit ctx: Context ) : List [ Type ]

Ensure that the first type in a list of parent types Ps points to a non-trait class. If that's not already the case, add one. The added class type CT is determined as follows. First, let C be the unique class such that - there is a parent P_i such that P_i derives from C, and - for every class D: If some parent P_j, j <= i derives from D, then C derives from D. Then, let CT be the smallest type which - has C as its class symbol, and - for all parents P_i: If P_i derives from C then P_i <:< CT.

[+] def ensureFirstTreeIsClass ( parents: List [ Tree ] , pos: Position ) ( implicit ctx: Context ) : List [ Tree ]
[+] protected def ensureNoLocalRefs ( tree: Tree , pt: Type , localSyms: => List [ Symbol ] ) ( implicit ctx: Context ) : Tree

Ensure that an expression's type can be expressed without references to locally defined symbols. This is done by adding a type ascription of a widened type that does not refer to the locally defined symbols. The widened type is computed using TyperAssigner#avoid. However, if the expected type is fully defined and not a supertype of the widened type, we ascribe with the expected type instead.

There's a special case having to do with anonymous classes. Sometimes the expected type of a block is the anonymous class defined inside it. In that case there's technically a leak which is not removed by the ascription.

[+] def escapingRefs ( block: Tree , localSyms: => List [ Symbol ] ) ( implicit ctx: Context ) : Set [ NamedType ]
[+] def gadtContext ( gadtSyms: Set [ Symbol ] ) ( implicit ctx: Context ) : FreshContext

Context with fresh GADT bounds for all gadtSyms

[+] def gadtSyms ( selType: Type ) ( implicit ctx: Context ) : Set [ Symbol ]

gadtSyms = "all type parameters of enclosing methods that appear non-variantly in the selector type" todo: should typevars which appear with variances +1 and -1 (in different places) be considered as well?

[+] protected def inlineExpansion ( mdef: DefDef ) ( implicit ctx: Context ) : Tree

Given a transparent method mdef, the method rewritten so that its body uses accessors to access non-public members. Overwritten in Retyper to return mdef unchanged.

[+] def isApplyProto ( pt: Type ) ( implicit ctx: Context ) : Boolean

Is pt a prototype of an apply selection, or a parameterless function yielding one?

[+] def localDummy ( cls: ClassSymbol , impl: Template ) ( implicit ctx: Context ) : Symbol
[+] protected def localTyper ( sym: Symbol ) : Typer
[+] protected def makeImplicitFunction ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def newLikeThis : Typer
[+] private def patchFinalVals ( vdef: ValDef ) ( implicit ctx: Context ) : Unit

Adds transparent to final vals with idempotent rhs

duplicating scalac behavior: for final vals that have rhs as constant, we do not create a field and instead return the value. This seemingly minor optimization has huge effect on initialization order and the values that can be observed during superconstructor call

see remark about idempotency in TreeInfo#constToLiteral

[+] private def patchIfLazy ( vdef: ValDef ) ( implicit ctx: Context ) : Unit

Add a @volitile to lazy vals when rewriting from Scala2

[+] protected def retrieveSym ( tree: Tree ) ( implicit ctx: Context ) : Symbol

Retrieve symbol attached to given tree

[+] protected def simplify ( tree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : tree.type

Interpolate and simplify the type of the given tree.

[+] def tryAlternatively ( op1: Context => T ) ( op2: Context => T ) ( implicit ctx: Context ) : T

Try op1, if there are errors, try op2, if op2 also causes errors, fall back to errors and result of op1.

[+] def tryEither ( op: Context => T ) ( fallBack: (T, TyperState) => T ) ( implicit ctx: Context ) : T
[+] def tryInsertApplyOrImplicit ( tree: Tree , pt: ProtoType , locked: TypeVars ) ( fallBack: => Tree ) ( implicit ctx: Context ) : Tree

Potentially add apply node or implicit conversions. Before trying either, if the function is applied to an empty parameter list (), we try

0th strategy: If tree overrides a nullary method, mark the prototype so that the argument is dropped and return tree itself. (but do this at most once per tree).

After that, two strategies are tried, and the first that is successful is picked.

1st strategy: Try to insert .apply so that the result conforms to prototype pt. This strategy is not tried if the prototype represents already another .apply or .apply() selection.

2nd strategy: If tree is a select qual.name, try to insert an implicit conversion around the qualifier part qual so that the result conforms to the expected type with wildcard result type.

If neither of the strategies are successful, continues with the apply result if an apply insertion was tried and tree has an apply method, or continues with fallBack otherwise. fallBack is supposed to always give an error.

[+] def tryInsertImplicitOnQualifier ( tree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : Option [ Tree ]

If this tree is a select node qual.name, try to insert an implicit conversion c around qual so that c(qual).name conforms to pt.

[+] def tryWithClassTag ( tree: Typed , pt: Type ) ( implicit ctx: Context ) : Tree

For a typed tree e: T, if T is an abstract type for which an implicit class tag ctag exists, rewrite to ctag(e).

[+] def typed ( tree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : Tree

Typecheck and adapt tree, returning a typed tree. Parameters as for typedUnadapted

[+] def typed ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typed$default$2 : WildcardType.type
[+] def typedAlternative ( tree: Alternative , pt: Type ) ( implicit ctx: Context ) : Alternative
[+] def typedAndTypeTree ( tree: AndTypeTree ) ( implicit ctx: Context ) : AndTypeTree
[+] def typedAnnotated ( tree: Annotated , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedAnnotation ( annot: Tree ) ( implicit ctx: Context ) : Tree
[+] def typedAppliedTypeTree ( tree: AppliedTypeTree ) ( implicit ctx: Context ) : Tree
[+] def typedAsFunction ( tree: PostfixOp , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedAssign ( tree: Assign , pt: Type ) ( implicit ctx: Context ) : Tree [ Type ]
[+] def typedBind ( tree: Bind , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedBlock ( tree: Block , pt: Type ) ( implicit ctx: Context ) : Tree [ Type ]
[+] def typedBlockStats ( stats: List [ Tree ] ) ( implicit ctx: Context ) : ( Context, List [ Tree ] )
[+] def typedByNameTypeTree ( tree: ByNameTypeTree ) ( implicit ctx: Context ) : ByNameTypeTree
[+] def typedCase ( tree: CaseDef , selType: Type , pt: Type , gadtSyms: Set [ Symbol ] ) ( implicit ctx: Context ) : CaseDef

Type a case.

[+] def typedCases ( cases: List [ CaseDef ] , selType: Type , pt: Type ) ( implicit ctx: Context ) : List [ CaseDef [ Type ] ]
[+] def typedClassDef ( cdef: TypeDef , cls: ClassSymbol ) ( implicit ctx: Context ) : Tree
[+] def typedClosure ( tree: Closure , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedDefDef ( ddef: DefDef , sym: Symbol ) ( implicit ctx: Context ) : Tree
[+] def typedExpr ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedExpr$default$2 : WildcardType.type
[+] def typedFunction ( tree: Function , pt: Type ) ( implicit ctx: Context ) : Tree [ Type ]
[+] def typedFunctionType ( tree: Function , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedFunctionValue ( tree: Function , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedIdent ( tree: Ident , pt: Type ) ( implicit ctx: Context ) : Tree

Attribute an identifier consisting of a simple name or wildcard

[+] def typedIf ( tree: If , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedImport ( imp: Import , sym: Symbol ) ( implicit ctx: Context ) : Import
[+] def typedInfixOp ( tree: InfixOp , pt: Type ) ( implicit ctx: Context ) : Tree

Translate infix operation expression l op r to

l.op(r) if op is left-associative { val x = l; r.op(l) } if op is right-associative call-by-value and l is impure r.op(l) if op is right-associative call-by-name or l is pure

[+] def typedInlined ( tree: Inlined , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedLambdaTypeTree ( tree: LambdaTypeTree ) ( implicit ctx: Context ) : Tree
[+] def typedLiteral ( tree: Literal ) ( implicit ctx: Context ) : Tree
[+] def typedMatch ( tree: Match , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedMatchFinish ( tree: Match , sel: Tree , selType: Type , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedNamedArg ( tree: NamedArg , pt: Type ) ( implicit ctx: Context ) : NamedArg [ Type ]
[+] def typedNew ( tree: New , pt: Type ) ( implicit ctx: Context ) : Tree [ Type ]
[+] def typedOrTypeTree ( tree: OrTypeTree ) ( implicit ctx: Context ) : OrTypeTree
[+] def typedPackageDef ( tree: PackageDef ) ( implicit ctx: Context ) : Tree
[+] def typedPattern ( tree: Tree , selType: Type ) ( implicit ctx: Context ) : Tree
[+] def typedPattern$default$2 : WildcardType.type
[+] def typedRefinedTypeTree ( tree: RefinedTypeTree ) ( implicit ctx: Context ) : RefinedTypeTree
[+] def typedReturn ( tree: Return ) ( implicit ctx: Context ) : Return
[+] private def typedSelect ( tree: Select , pt: Type , qual: Tree ) ( implicit ctx: Context ) : Select
[+] def typedSelect ( tree: Select , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedSeqLiteral ( tree: SeqLiteral , pt: Type ) ( implicit ctx: Context ) : SeqLiteral
[+] def typedSingletonTypeTree ( tree: SingletonTypeTree ) ( implicit ctx: Context ) : SingletonTypeTree
[+] def typedStats ( stats: List [ Tree ] , exprOwner: Symbol ) ( implicit ctx: Context ) : List [ Tree ]
[+] def typedSuper ( tree: Super , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedThis ( tree: This ) ( implicit ctx: Context ) : Tree
[+] def typedThrow ( tree: Throw ) ( implicit ctx: Context ) : Tree
[+] def typedTrees ( trees: List [ Tree ] ) ( implicit ctx: Context ) : List [ Tree ]
[+] def typedTry ( tree: Try , pt: Type ) ( implicit ctx: Context ) : Try
[+] def typedType ( tree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedType$default$2 : WildcardType.type
[+] def typedTypeBoundsTree ( tree: TypeBoundsTree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedTypeDef ( tdef: TypeDef , sym: Symbol ) ( implicit ctx: Context ) : Tree
[+] def typedTypeTree ( tree: TypeTree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedTyped ( tree: Typed , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedTypedSplice ( tree: TypedSplice ) ( implicit ctx: Context ) : Tree
[+] def typedUnadapted ( initTree: Tree , pt: Type ) ( implicit ctx: Context ) : Tree
[+] def typedUnadapted ( initTree: Tree , pt: Type , locked: TypeVars ) ( implicit ctx: Context ) : Tree

Typecheck tree without adapting it, returning a typed tree.

[+] def typedUnadapted$default$2 : WildcardType.type
[+] def typedValDef ( vdef: ValDef , sym: Symbol ) ( implicit ctx: Context ) : Tree