abstract class Typer extends Analyzer.TyperDiagnostics with Analyzer.Adaptation with Analyzer.Tag with Analyzer.PatternTyper with Analyzer.TyperContextErrors
- Alphabetic
- By Inheritance
- Typer
- TyperContextErrors
- PatternTyper
- Tag
- Adaptation
- TyperDiagnostics
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Typer(context0: Analyzer.Context)
Value Members
-
object
TyperErrorGen
- Definition Classes
- TyperContextErrors
-
object
checkDead
- Definition Classes
- TyperDiagnostics
-
object
checkUnused
- Definition Classes
- TyperDiagnostics
- def adaptAfterOverloadResolution(tree: Global.Tree, mode: Mode, pt: Global.Type = WildcardType, original: Global.Tree = EmptyTree): Global.Tree
- def adaptCase(cdef: Global.CaseDef, mode: Mode, tpe: Global.Type): Global.CaseDef
-
def
adaptToArguments(qual: Global.Tree, name: Global.Name, args: List[Global.Tree], pt: Global.Type, reportAmbiguous: Boolean = true, saveErrors: Boolean = true): Global.Tree
Try to apply an implicit conversion to
qual
to that it contains a methodname
which can be applied to argumentsargs
with expected typept
.Try to apply an implicit conversion to
qual
to that it contains a methodname
which can be applied to argumentsargs
with expected typept
. Ifpt
is defined, there is a fallback to try again with pt = ?. This helps avoiding propagating result information too far and solves #1756. If no conversion is found, returnqual
unchanged. - def adaptToMember(qual: Global.Tree, searchTemplate: Global.Type, reportAmbiguous: Boolean = true, saveErrors: Boolean = true): Global.Tree
-
def
adaptToMemberWithArgs(tree: Global.Tree, qual: Global.Tree, name: Global.Name, mode: Mode, reportAmbiguous: Boolean = true, saveErrors: Boolean = true): Global.Tree
Try to apply an implicit conversion to
qual
so that it contains a methodname
.Try to apply an implicit conversion to
qual
so that it contains a methodname
. If that's ambiguous try taking arguments into account usingadaptToArguments
. -
def
adaptToName(qual: Global.Tree, name: Global.Name): Global.Tree
Try to apply an implicit conversion to
qual
to that it contains a membername
of arbitrary type.Try to apply an implicit conversion to
qual
to that it contains a membername
of arbitrary type. If no conversion is found, returnqual
unchanged. -
def
applyImplicitArgs(fun: Global.Tree): Global.Tree
Find implicit arguments and pass them to given tree.
- def atOwner(tree: Global.Tree, owner: Global.Symbol): Analyzer.Typer
- def atOwner(owner: Global.Symbol): Analyzer.Typer
- def callToCompanionConstr(context: Analyzer.Context, calledFun: Global.Symbol): Boolean
-
def
canAdaptConstantTypeToLiteral: Boolean
Overridden to false in scaladoc and/or interactive.
- def canTranslateEmptyListToNil: Boolean
-
def
checkClassType(tpt: Global.Tree): Boolean
Check that
tpt
refers to a non-refinement class type - def checkExistentialsFeature(pos: Global.Position, tpe: Global.Type, prefix: String): AnyVal
-
def
checkFeature(pos: Global.Position, featureTrait: Global.Symbol, construct: ⇒ String = "", immediate: Boolean = false): Boolean
Check whether feature given by
featureTrait
is enabled.Check whether feature given by
featureTrait
is enabled. If it is not, issue an error or a warning depending on whether the feature is required.- construct
A string expression that is substituted for "#" in the feature description string
- immediate
When set, feature check is run immediately, otherwise it is run at the end of the typechecking run for the enclosing unit. This is done to avoid potential cyclic reference errors by implicits that are forced too early.
- returns
if feature check is run immediately: true if feature is enabled, false otherwise if feature check is delayed or suppressed because we are past typer: true
- def checkFinitary(classinfo: Global.ClassInfoType): Unit
-
def
checkMethodStructuralCompatible(ddef: Global.DefDef): Unit
Check if a structurally defined method violates implementation restrictions.
Check if a structurally defined method violates implementation restrictions. A method cannot be called if it is a non-private member of a refinement type and if its parameter's types are any of:
- the self-type of the refinement
- a type member of the refinement
- an abstract type declared outside of the refinement.
- an instance of a value class Furthermore, the result type may not be a value class either
- def checkNonCyclic(defn: Global.Tree, tpt: Global.Tree): Unit
- def checkNonCyclic(sym: Global.Symbol): Unit
- def checkNonCyclic(pos: Global.Position, tp: Global.Type, lockedSym: Global.Symbol): Boolean
-
def
checkNonCyclic(pos: Global.Position, tp: Global.Type): Boolean
Check that type
tp
is not a subtype of itself. - def checkParamsConvertible(tree: Global.Tree, tpe0: Global.Type): Unit
-
def
checkStablePrefixClassType(tpt: Global.Tree): Boolean
Check that
tpt
refers to a class type with a stable prefix. -
def
checkValidAdaptation(t: Global.Tree, args: List[Global.Tree]): Boolean
- Definition Classes
- Adaptation
- def computeMacroDefType(ddef: Global.DefDef, pt: Global.Type): Global.Type
-
def
computeParamAliases(clazz: Global.Symbol, vparamss: List[List[Global.ValDef]], rhs: Global.Tree): Unit
Enter all aliases of local parameter accessors.
- def computeType(tree: Global.Tree, pt: Global.Type): Global.Type
-
final
def
constrTyperIf(inConstr: Boolean): Analyzer.Typer
The typer for an expression, depending on where we are.
The typer for an expression, depending on where we are. If we are before a superclass call, this is a typer over a constructor context; otherwise it is the current typer.
- var context: Analyzer.Context
- def context1: Analyzer.Context
-
def
cyclicReferenceMessage(sym: Global.Symbol, tree: Global.Tree): Option[String]
Returns Some(msg) if the given tree is untyped apparently due to a cyclic reference, and None otherwise.
Returns Some(msg) if the given tree is untyped apparently due to a cyclic reference, and None otherwise.
- Definition Classes
- TyperDiagnostics
- def doTypedApply(tree: Global.Tree, fun0: Global.Tree, args: List[Global.Tree], mode: Mode, pt: Global.Type): Global.Tree
-
def
doTypedUnapply(tree: Global.Tree, funOrig: Global.Tree, funOverloadResolved: Global.Tree, args: List[Global.Tree], mode: Mode, pt: Global.Type): Global.Tree
- Definition Classes
- PatternTyper
- def dropExistential(tp: Global.Type): Global.Type
-
def
extractorForUncheckedType(pos: Global.Position, pt: Global.Type): Global.Tree
- Definition Classes
- PatternTyper
- val infer: Analyzer.Inferencer
-
def
inferSamType(fun: Global.Tree, pt: Global.Type, mode: Mode): Boolean
Synthesize and type check the implementation of a type with a Single Abstract Method.
Synthesize and type check the implementation of a type with a Single Abstract Method.
Based on a type checked Function node
{ (p1: T1, ..., pN: TN) => body } : S
whereS
is the expected type that defines a single abstract method (call itapply
for the example), that has signature(p1: T1', ..., pN: TN'): T'
, synthesize the instantiation of the following anonymous classnew S { def apply$body(p1: T1, ..., pN: TN): T = body def apply(p1: T1', ..., pN: TN'): T' = apply$body(p1,..., pN) }
The
apply
method is identified by the argumentsam
;S
corresponds to the argumentpt
, Ifpt
is not fully defined, we derivesamClassTpFullyDefined
by inferring any unknown type parameters.The types T1' ... TN' and T' are derived from the method signature of the sam method, as seen from the fully defined
samClassTpFullyDefined
.The function's body is put in a (static) method in the class definition to enforce scoping. S's members should not be in scope in
body
. (Putting it in the block outside the class runs into implementation problems described below)The restriction on implicit arguments (neither S's constructor, nor sam may take an implicit argument list), is to keep the implementation of type inference (the computation of
samClassTpFullyDefined
) simple.Impl notes:
fun
has a FunctionType, but the expected typept
is some SAM type -- let's remedy thatfun
is fully attributed, so we'll have to wrangle some symbols into shape (owner change, vparam syms)- after experimentation, it works best to type check function literals fully first and then adapt to a sam type, as opposed to a sam-specific code paths earlier on in type checking (in typedFunction). For one, we want to emit the same bytecode regardless of whether the expected function type is a built-in FunctionN or some SAM type
-
def
inferView(tree: Global.Tree, from: Global.Type, to: Global.Type, reportAmbiguous: Boolean = true, saveErrors: Boolean = true): Global.Tree
Infer an implicit conversion (
view
) between two types.Infer an implicit conversion (
view
) between two types.- tree
The tree which needs to be converted.
- from
The source type of the conversion
- to
The target type of the conversion
- reportAmbiguous
Should ambiguous implicit errors be reported? False iff we search for a view to find out whether one type is coercible to another.
- saveErrors
Should ambiguous and divergent implicit errors that were buffered during the inference of a view be put into the original buffer. False iff we don't care about them.
- def instantiate(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
-
def
instantiateExpectingUnit(tree: Global.Tree, mode: Mode): Global.Tree
If the expected type is Unit: try instantiating type arguments with expected type Unit, but if that fails, try again with pt = WildcardType and discard the expression.
- def instantiatePossiblyExpectingUnit(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
- def isCapturedExistential(sym: Global.Symbol): Boolean
-
def
isNamedApplyBlock(tree: Global.Tree): Boolean
Is
tree
a block created by a named application? - def isReferencedFrom(ctx: Analyzer.Context, sym: Global.Symbol): Boolean
-
def
isStale(sym: Global.Symbol): Boolean
A symbol is stale if it is toplevel, to be loaded from a classfile, and the classfile is produced from a sourcefile which is compiled in the current run.
-
def
labelTyper(ldef: Global.LabelDef): Analyzer.Typer
The typer for a label definition.
The typer for a label definition. If this is part of a template we first have to enter the label definition.
- final def lookupTransformed(tree: Global.Tree): Option[Global.Tree]
-
def
member(qual: Global.Tree, name: Global.Name): Global.Symbol
The member with given name of given qualifier tree
- def missingSelectErrorTree(tree: Global.Tree, qual: Global.Tree, name: Global.Name): Global.Tree
- def namer: Analyzer.Namer
-
def
needsInstantiation(tparams: List[Global.Symbol], formals: List[Global.Type], args: List[Global.Tree]): Boolean
Does function need to be instantiated, because a missing parameter in an argument closure overlaps with an uninstantiated formal?
- def packCaptured(tpe: Global.Type): Global.Type
-
def
packSymbols(hidden: List[Global.Symbol], tp: Global.Type): Global.Type
Compute an existential type from raw hidden symbols
syms
and typetp
-
def
packedType(tree: Global.Tree, owner: Global.Symbol): Global.Type
convert local symbols and skolems to existentials
- def packedTypes(trees: List[Global.Tree]): List[Global.Type]
-
def
permanentlyHiddenWarning(pos: Global.Position, hidden: Global.Name, defn: Global.Symbol): Unit
- Definition Classes
- TyperDiagnostics
- def phasedAppliedType(sym: Global.Symbol, args: List[Global.Type]): Global.Type
-
def
qualifyingClass(tree: Global.Tree, qual: Global.Name, packageOK: Boolean): Global.Symbol
The qualifying class of a this or super with prefix
qual
.The qualifying class of a this or super with prefix
qual
. packageOk is equal false when qualifying class symbol -
def
reallyExists(sym: Global.Symbol): Boolean
Is symbol defined and not stale?
- def reenterTypeParams(tparams: List[Global.TypeDef]): List[Global.Symbol]
- def reenterValueParams(vparamss: List[List[Global.ValDef]]): Unit
-
def
reportTypeError(context0: Analyzer.Context, pos: Global.Position, ex: Global.TypeError): Unit
Report a type error.
Report a type error.
- pos
The position where to report the error
- ex
The exception that caused the error
- Definition Classes
- TyperDiagnostics
-
def
resolveClassTag(pos: Global.Position, tp: Global.Type, allowMaterialization: Boolean = true): Global.Tree
Finds in scope or materializes a ClassTag.
Finds in scope or materializes a ClassTag. Should be used instead of ClassManifest every time compiler needs to persist an erasure.
Once upon a time, we had an
ErasureTag
which was toClassTag
the same thatWeakTypeTag
is forTypeTag
. However we found out that we don't really need this concept, so it got removed.- pos
Position for error reporting. Please, provide meaningful value.
- tp
Type we're looking a ClassTag for, e.g. resolveClassTag(pos, IntTpe) will look for ClassTag[Int].
- allowMaterialization
If true (default) then the resolver is allowed to launch materialization macros when there's no class tag in scope. If false then materialization macros are prohibited from running.
- returns
Tree that represents an
scala.reflect.ClassTag
fortp
if everything is okay. EmptyTree if the result contains unresolved (i.e. not spliced) type parameters and abstract type members. EmptyTree ifallowMaterialization
is false, and there is no class tag in scope.
- Definition Classes
- Tag
-
def
resolveTypeTag(pos: Global.Position, pre: Global.Type, tp: Global.Type, concrete: Boolean, allowMaterialization: Boolean = true): Global.Tree
Finds in scope or materializes an WeakTypeTag (if
concrete
is false) or a TypeTag (ifconcrete
is true).Finds in scope or materializes an WeakTypeTag (if
concrete
is false) or a TypeTag (ifconcrete
is true).- pos
Position for error reporting. Please, provide meaningful value.
- pre
Prefix that represents a universe this type tag will be bound to. If
pre
is set toNoType
, then any type tag in scope will do, regardless of its affiliation. Ifpre
is set toNoType
, and tag resolution involves materialization, thenmkRuntimeUniverseRef
will be used.- tp
Type we're looking a TypeTag for, e.g. resolveTypeTag(pos, mkRuntimeUniverseRef, IntTpe, false) will look for scala.reflect.runtime.universe.TypeTag[Int].
- concrete
If true then the result must not contain unresolved (i.e. not spliced) type parameters and abstract type members. If false then the function will always succeed (abstract types will be reified as free types).
- allowMaterialization
If true (default) then the resolver is allowed to launch materialization macros when there's no type tag in scope. If false then materialization macros are prohibited from running.
- returns
Tree that represents a
scala.reflect.TypeTag
fortp
if everything is okay. EmptyTree ifconcrete
is true and the result contains unresolved (i.e. not spliced) type parameters and abstract type members. EmptyTree ifallowMaterialization
is false, and there is no array tag in scope.
- Definition Classes
- Tag
-
def
rewrappingWrapperTrees(f: (Global.Tree) ⇒ List[Global.Tree]): (Global.Tree) ⇒ List[Global.Tree]
For flatMapping a list of trees when you want the DocDefs and Annotated to be transparent.
- val runDefinitions: reflect.internal.Definitions.definitions.RunDefinitions
-
def
samToFunctionType(tp: Global.Type, sam: Global.Symbol = NoSymbol): Global.Type
Convert a SAM type to the corresponding FunctionType, extrapolating BoundedWildcardTypes in the process (no type precision is lost by the extrapolation, but this facilitates dealing with the types arising from Java's use-site variance).
- def silent[T](op: (Analyzer.Typer) ⇒ T, reportAmbiguousErrors: Boolean = context.ambiguousErrors, newtree: Global.Tree = context.tree): Analyzer.SilentResult[T]
- def stabilizeFun(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
-
def
synthesizePartialFunction(paramName: Global.TermName, paramPos: Global.Position, paramSynthetic: Boolean, tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
synthesize and type check a PartialFunction implementation based on the match in
tree
synthesize and type check a PartialFunction implementation based on the match in
tree
param => sel match { cases }
becomes:new AbstractPartialFunction[$argTp, $matchResTp] { def applyOrElse[A1 <: $argTp, B1 >: $matchResTp]($param: A1, default: A1 => B1): B1 = $selector match { $cases } def isDefinedAt(x: $argTp): Boolean = $selector match { $casesTrue } }
TODO: it would be nicer to generate the tree specified above at once and type it as a whole, there are two gotchas:
- matchResTp may not be known until we've typed the match (can only use resTp when it's fully defined),
- if we typed the match in isolation first, you'd know its result type, but would have to re-jig the owner structure
- could we use a type variable for matchResTp and backpatch it?
- occurrences of
this
incases
orsel
must resolve to the this of the class originally enclosing the match, not of the anonymous partial function subclass
an alternative TODO: add partial function AST node or equivalent and get rid of this synthesis --> do everything in uncurry (or later) however, note that pattern matching codegen is designed to run *before* uncurry
- matchResTp may not be known until we've typed the match (can only use resTp when it's fully defined),
-
final
def
transformedOr(tree: Global.Tree, op: ⇒ Global.Tree): Global.Tree
- Annotations
- @inline()
- final def transformedOrTyped(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
- def typed(tree: Global.Tree, mode: Mode): Global.Tree
-
def
typed(tree: Global.Tree, pt: Global.Type): Global.Tree
Types expression
tree
with given prototypept
. -
def
typed(tree: Global.Tree): Global.Tree
Types expression or definition
tree
. - def typed(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
- def typed1(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
-
def
typedAnnotation(ann: Global.Tree, mode: Mode = EXPRmode): Global.AnnotationInfo
Convert an annotation constructor call into an AnnotationInfo.
- def typedArg(arg: Global.Tree, mode: Mode, newmode: Mode, pt: Global.Type): Global.Tree
- def typedArgs(args: List[Global.Tree], mode: Mode): collection.immutable.List[Global.Tree]
-
def
typedArgsForFormals(args: List[Global.Tree], formals: List[Global.Type], mode: Mode): List[Global.Tree]
- Definition Classes
- PatternTyper
- def typedBlock(block0: Global.Block, mode: Mode, pt: Global.Type): Global.Block
- def typedByValueExpr(tree: Global.Tree, pt: Global.Type = WildcardType): Global.Tree
- def typedCase(cdef: Global.CaseDef, pattpe: Global.Type, pt: Global.Type): Global.CaseDef
- def typedCases(cases: List[Global.CaseDef], pattp: Global.Type, pt: Global.Type): List[Global.CaseDef]
- def typedClassDef(cdef: Global.ClassDef): Global.Tree
- def typedClassOf(tree: Global.Tree, tpt: Global.Tree, noGen: Boolean = false): Global.Tree
-
def
typedConstructorPattern(fun0: Global.Tree, pt: Global.Type): Global.Tree
- Definition Classes
- PatternTyper
- def typedDefDef(ddef: Global.DefDef): Global.DefDef
- def typedDocDef(docDef: Global.DocDef, mode: Mode, pt: Global.Type): Global.Tree
- def typedHigherKindedType(tree: Global.Tree, mode: Mode): Global.Tree
-
def
typedHigherKindedType(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
Types a higher-kinded type tree -- pt denotes the expected kind and must be one of
Kind.WildCard
andKind.FromParams
- def typedImport(imp: Global.Import): Global.Import
- def typedLabelDef(ldef: Global.LabelDef): Global.LabelDef
- def typedMatch(selector: Global.Tree, cases: List[Global.CaseDef], mode: Mode, pt: Global.Type, tree: Global.Tree = EmptyTree): Global.Match
-
def
typedModifiers(mods: Global.Modifiers): Global.Modifiers
Remove definition annotations from modifiers (they have been saved into the symbol's
annotations
in the type completer / namer)Remove definition annotations from modifiers (they have been saved into the symbol's
annotations
in the type completer / namer)However reification does need annotation definitions to proceed. Unfortunately, AnnotationInfo doesn't provide enough info to reify it in general case. The biggest problem is with the "atp: Type" field, which cannot be reified in some situations that involve locally defined annotations. See more about that in Reifiers.scala.
That's why the original tree gets saved into
original
field of AnnotationInfo (happens elsewhere). The field doesn't get pickled/unpickled and exists only during a single compilation run. This simultaneously allows us to reify annotations and to preserve backward compatibility. - def typedModuleDef(mdef: Global.ModuleDef): Global.Tree
-
def
typedOperator(tree: Global.Tree): Global.Tree
Types function part of an application
- def typedParentTypes(templ: Global.Template): List[Global.Tree]
-
def
typedPattern(tree: Global.Tree, pt: Global.Type): Global.Tree
Types a pattern with prototype
pt
- def typedPos(pos: Global.Position)(tree: Global.Tree): Global.Tree
- def typedPos(pos: Global.Position, mode: Mode, pt: Global.Type)(tree: Global.Tree): Global.Tree
- def typedQualifier(tree: Global.Tree): Global.Tree
-
def
typedQualifier(tree: Global.Tree, mode: Mode): Global.Tree
Types qualifier
tree
of a select node.Types qualifier
tree
of a select node. E.g. is tree occurs in a context liketree.m
. -
def
typedQualifier(tree: Global.Tree, mode: Mode, pt: Global.Type): Global.Tree
Types qualifier
tree
of a select node.Types qualifier
tree
of a select node. E.g. is tree occurs in a context liketree.m
. - def typedRefinement(templ: Global.Template): Unit
- def typedStats(stats: List[Global.Tree], exprOwner: Global.Symbol, warnPure: Boolean = true): List[Global.Tree]
-
def
typedTemplate(templ0: Global.Template, parents1: List[Global.Tree]): Global.Template
Check that inner classes do not inherit from Annotation
-
def
typedType(tree: Global.Tree): Global.Tree
Types a (fully parameterized) type tree
-
def
typedType(tree: Global.Tree, mode: Mode): Global.Tree
Types a (fully parameterized) type tree
- def typedTypeConstructor(tree: Global.Tree): Global.Tree
-
def
typedTypeConstructor(tree: Global.Tree, mode: Mode): Global.Tree
Types a type constructor tree used in a new or supertype
- def typedTypeDef(tdef: Global.TypeDef): Global.TypeDef
- def typedValDef(vdef: Global.ValDef): Global.ValDef
-
final
def
typerWithCondLocalContext[T](c: ⇒ Analyzer.Context)(cond: Boolean)(f: (Analyzer.Typer) ⇒ T): T
- Annotations
- @inline()
-
final
def
typerWithLocalContext[T](c: Analyzer.Context)(f: (Analyzer.Typer) ⇒ T): T
- Annotations
- @inline()
-
def
validateParentClasses(parents: List[Global.Tree], selfType: Global.Type): Unit
Check that
Check that
- all parents are class types,
- first parent class is not a mixin; following classes are mixins,
- final classes are not inherited,
- sealed classes are only inherited by classes which are nested within definition of base class, or that occur within same statement sequence,
- self-type of current class is a subtype of self-type of each parent class.
- no two parents define same symbol.
- def viewExists(from: Global.Type, to: Global.Type): Boolean
- def virtualizedMatch(match_: Global.Match, mode: Mode, pt: Global.Type): Global.Tree
-
def
warnTypeParameterShadow(tparams: List[Global.TypeDef], sym: Global.Symbol): Unit
- Definition Classes
- TyperDiagnostics
-
final
def
withCondConstrTyper[T](inConstr: Boolean)(f: (Analyzer.Typer) ⇒ T): T
- Annotations
- @inline()
-
def
wrapClassTagUnapply(uncheckedPattern: Global.Tree, classTagExtractor: Global.Tree, pt: Global.Type): Global.Tree
- Definition Classes
- PatternTyper
-
object
checkNoEscaping extends Global.TypeMap
Check that type of given tree does not contain local or private components.
- object dyna
The Scala compiler and reflection APIs.