scala.tools.nsc.typechecker.TreeCheckers
Perform the following adaptations of expression, pattern or type tree
wrt to
given mode mode
and given prototype pt
:
(-1) For expressions with annotated types, let AnnotationCheckers decide what to do
(0) Convert expressions with constant types to literals (unless in interactive/scaladoc mode)
(1) Resolve overloading, unless mode contains FUNmode
(2) Apply parameterless functions
(3) Apply polymorphic types to fresh instances of their type parameters and
store these instances in context.
Perform the following adaptations of expression, pattern or type tree
wrt to
given mode mode
and given prototype pt
:
(-1) For expressions with annotated types, let AnnotationCheckers decide what to do
(0) Convert expressions with constant types to literals (unless in interactive/scaladoc mode)
(1) Resolve overloading, unless mode contains FUNmode
(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
Try to apply an implicit conversion to qual
to that it contains
a method name
which can be applied to arguments args
with expected type pt
.
Try to apply an implicit conversion to qual
to that it contains
a method name
which can be applied to arguments args
with expected type pt
.
If pt
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, return qual
unchanged.
Try to apply an implicit conversion to qual
so that it contains
a method name
.
Try to apply an implicit conversion to qual
so that it contains
a method name
. If that's ambiguous try taking arguments into
account using adaptToArguments
.
Try to apply an implicit conversion to qual
to that it contains a
member name
of arbitrary type.
Try to apply an implicit conversion to qual
to that it contains a
member name
of arbitrary type.
If no conversion is found, return qual
unchanged.
Find implicit arguments and pass them to given tree.
Find implicit arguments and pass them to given tree.
Check that tpt
refers to a non-refinement class type
Check that tpt
refers to a non-refinement class type
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.
A string expression that is substituted for "#" in the feature description string
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.
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
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:
Check that type of given tree does not contain local or private components.
Check that type tp
is not a subtype of itself.
Check that type tp
is not a subtype of itself.
...
...
true
if tp
is not a subtype of itself.
Check that tree
is a stable expression.
Check that tpt
refers to a class type with a stable prefix.
Check that tpt
refers to a class type with a stable prefix.
Enter all aliases of local parameter accessors.
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.
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.
If we map a set of hidden symbols to their existential bounds, we have a problem: the bounds may themselves contain references to the hidden symbols.
If we map a set of hidden symbols to their existential bounds, we have a problem: the bounds may themselves contain references to the hidden symbols. So this recursively calls existentialBound until the typeSymbol is not amongst the symbols being hidden.
Given a set rawSyms
of term- and type-symbols, and a type
tp
, produce a set of fresh type parameters and a type so that
it can be abstracted to an existential type.
Given a set rawSyms
of term- and type-symbols, and a type
tp
, produce a set of fresh type parameters and a type so that
it can be abstracted to an existential type. Every type symbol
T
in rawSyms
is mapped to a clone. Every term symbol x
of
type T
in rawSyms
is given an associated type symbol of the
following form:
type x.type <: T with Singleton
The name of the type parameter is x.type
, to produce nice
diagnostics. The Singleton parent ensures that the type
parameter is still seen as a stable type. Type symbols in
rawSyms are fully replaced by the new symbols. Term symbols are
also replaced, except for term symbols of an Ident tree, where
only the type of the Ident is changed.
In order to override this in the TreeCheckers Typer so synthetics aren't re-added all the time, it is exposed here the module/class typing methods go through it.
In order to override this in the TreeCheckers Typer so synthetics aren't re-added all the time, it is exposed here the module/class typing methods go through it. ...but it turns out it's also the ideal spot for namer/typer coordination for the tricky method synthesis scenarios, so we'll make it that.
Infer an implicit conversion (view) between two types.
Infer an implicit conversion (view) between two types.
The tree which needs to be converted.
The source type of the conversion
The target type of the conversion
Should ambiguous implicit errors be reported? False iff we search for a view to find out whether one type is coercible to another.
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.
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.
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.
Is tree
a block created by a named application?
Is tree
a block created by a named application?
Would tree be a stable (i.
Would tree be a stable (i.e. a pure expression) if the type of its symbol was not volatile?
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.
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.
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.
The member with given name of given qualifier tree
The member with given name of given qualifier tree
Does function need to be instantiated, because a missing parameter in an argument closure overlaps with an uninstantiated formal?
Does function need to be instantiated, because a missing parameter in an argument closure overlaps with an uninstantiated formal?
Compute an existential type from raw hidden symbols syms
and type tp
Compute an existential type from raw hidden symbols syms
and type tp
convert local symbols and skolems to existentials
convert local symbols and skolems to existentials
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
Is symbol defined and not stale?
Is symbol defined and not stale?
Report a type error.
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 to ClassTag
the same that AbsTypeTag
is for TypeTag
.
However we found out that we don't really need this concept, so it got removed.
Position for error reporting. Please, provide meaningful value.
Type we're looking a ClassTag for, e.g. resolveClassTag(pos, IntClass.tpe) will look for ClassTag[Int].
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.
Finds in scope or materializes an AbsTypeTag (if concrete
is false) or a TypeTag (if concrete
is true).
Finds in scope or materializes an AbsTypeTag (if concrete
is false) or a TypeTag (if concrete
is true).
Position for error reporting. Please, provide meaningful value.
Prefix that represents a universe this type tag will be bound to.
If pre
is set to NoType
, then any type tag in scope will do, regardless of its affiliation.
If pre
is set to NoType
, and tag resolution involves materialization, then mkBasisPrefix
will be used.
Type we're looking a TypeTag for, e.g. resolveTypeTag(pos, reflectBasisPrefix, IntClass.tpe, false) will look for scala.reflect.basis.TypeTag[Int].
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).
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.
For flatMapping a list of trees when you want the DocDefs and Annotated to be transparent.
For flatMapping a list of trees when you want the DocDefs and Annotated to be transparent.
...
...
...
...
...
...
...
...
Types expression tree
with given prototype pt
.
Types expression or definition tree
.
Convert an annotation constructor call into an AnnotationInfo.
Convert an annotation constructor call into an AnnotationInfo.
the expected annotation class
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Types a higher-kinded type tree -- pt denotes the expected kind
Types a higher-kinded type tree -- pt denotes the expected kind
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.
...
...
Types function part of an application
Types function part of an application
Types a pattern with prototype pt
Types a pattern with prototype pt
Types qualifier tree
of a select node.
Types qualifier tree
of a select node.
E.g. is tree occurs in a context like tree.m
.
Types qualifier tree
of a select node.
Types qualifier tree
of a select node.
E.g. is tree occurs in a context like tree.m
.
...
...
- Check that inner classes do not inherit from Annotation
...
Types a (fully parameterized) type tree
Types a (fully parameterized) type tree
Types a (fully parameterized) type tree
Types a (fully parameterized) type tree
Types a type constructor tree used in a new or supertype
Types a type constructor tree used in a new or supertype
...
...
Check that
Check that
- sealed classes are only inherited by classes which are nested within definition of base class, or that occur within same statement sequence,
(treeChecker: StringAdd).self
(treeChecker: StringFormat).self
(treeChecker: ArrowAssoc[TreeChecker]).x
(Since version 2.10.0) Use leftOfArrow
instead
(treeChecker: Ensuring[TreeChecker]).x
(Since version 2.10.0) Use resultOfEnsuring
instead