scala.tools.nsc.typechecker.Contexts
Is this context in all modes in the given mask
?
A bitmask containing all the boolean flags in a context, e.
A bitmask containing all the boolean flags in a context, e.g. are implicit views enabled
These messages are printed when issuing an error
The next outer context whose tree is a template or package definition
The next enclosing context (potentially this
) that is owned by a class or method
The next outer context whose tree is a method
.
...or an Apply.
The next enclosing context (potentially this
) that has a CaseDef
as a tree
Return the closest enclosing context that defines a subclass of clazz
or a companion object thereof, or NoContext
if no such context exists.
Issue/throw the given error message according to the current mode for error reporting.
Issue/throw the given err
according to the current mode for error reporting.
Return and clear the undetermined type parameters
The first error, if any, in the report buffer
Equivalent to imports.headOption
, but more efficient
Issue and clear all warnings from the report buffer
Return and clear all errors from the report buffer
Clear all errors from the report buffer
Does the report buffer contain any errors?
The symbol with name name
imported via the import in imp
,
if any such symbol is accessible from this context.
The currently visible imports
true if the expr
evaluates to true within a silent Context that incurs no errors
Is sym
accessible as a member of pre
in current context?
Is sym
defined in package object of package pkg
?
Since sym may be defined in some parent of the package object,
we cannot inspect its owner only; we have to go through the
info of the package object.
Is sym
defined in package object of package pkg
?
Since sym may be defined in some parent of the package object,
we cannot inspect its owner only; we have to go through the
info of the package object. However to avoid cycles we'll check
what other ways we can before pushing that way.
Issue/buffer/throw the given type error according to the current mode for error reporting.
Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting.
Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting.
Find a symbol in this context or one of its outers.
Find a symbol in this context or one of its outers.
Used to find symbols are owned by methods (or fields), they can't be found in some scope.
Examples: companion module of classes owned by a method, default getter methods of nested methods. See NamesDefaults.scala
Find the symbol of a simple name starting from this context.
Find the symbol of a simple name starting from this context. All names are filtered through the "qualifies" predicate, the search continuing as long as no qualifying name is found.
Construct a child context.
Construct a child context. The parent and child will share the report buffer.
Compare with makeSilent
, in which the child has a fresh report buffer.
If tree
is an Import
, that import will be avaiable at the head of
Context#imports
.
A context for typing constructor parameter ValDefs, super or self invocation arguments and default getters of constructors.
A context for typing constructor parameter ValDefs, super or self invocation arguments and default getters of constructors. These expressions need to be type checked in a scope outside the class, cf. spec 5.3.1.
This method is called by namer / typer where this
is the context for the constructor DefDef. The
owner of the resulting (new) context is the outer context for the Template, i.e. the context for the
ClassDef. This means that class type parameters will be in scope. The value parameters of the current
constructor are also entered into the new constructor scope. Members of the class however will not be
accessible.
Make a silent child context does not allow implicits.
Make a silent child context does not allow implicits. Used to prevent chaining of implicit views.
Make a child context that represents a new nested scope
Make a child context that buffers errors and warnings into a fresh report buffer.
Types for which implicit arguments are currently searched
The current owner
A buffer for errors and warnings, used with this.bufferErrors == true
Discard the current report buffer, and replace with other
Saved type bounds for type parameters which are narrowed in a GADT.
Run body
with this context with no undetermined type parameters, restore the original
the original list afterwards.
Run body
with this context with no undetermined type parameters, restore the original
the original list afterwards.
Should ambiguous errors be reported during evaluation of body
?
The current scope
Set all modes in the mask enable
to true, and all in disable
to false.
Tree associated with this context
Undetermined type parameters.
Undetermined type parameters. See Infer#{inferExprInstance, adjustTypeArgs}
. Not inherited to child contexts
Update all modes in mask
to value
Append the given errors to the report buffer
Discard the current report buffer, and replace with an empty one
Variance relative to enclosing class
Issue/throw the given error message according to the current mode for error reporting.
TypeConstructorAllowed is enabled when we are typing a higher-kinded type.
TypeConstructorAllowed is enabled when we are typing a higher-kinded type. adapt should then check kind-arity based on the prototypical type's kind arity. Type arguments should not be inferred.
A motley collection of the state and loosely associated behaviour of the type checker. Each
Typer
has an associated context, and as it descends into the tree new(Typer, Context)
pairs are spawned.Meet the crew; first the state:
outer
.contextMode
.And behaviour:
Context
is something of a Zipper for the tree were are typechecking: itenclosingContextChain
is the path back to the root. This is exactly what we need to resolve names (lookupSymbol
) and to collect in-scope implicit defintions (implicitss
) Supporting these areimports
, which represents allImport
trees in in the enclosing context chain.isAccessible
.)More on error buffering: When are type errors recoverable? In quite a few places, it turns out. Some examples: trying to type an application with/without the expected type, or with/without implicit views enabled. This is usually mediated by
Typer.silent
,Inferencer#tryTwice
.Intially, starting from the
typer
phase, the contexts either buffer or report errors; afterwards errors are thrown. This is configured inrootContext
. Additionally, more fine grained control is needed based on the kind of error; ambiguity errors are often suppressed during exploraratory typing, such as determining whethera == b
in an argument position is an assignment or a named argument, whenInfererencer#isApplicableSafe
type checks applications with and without an expected type, or whtnTyper#tryTypedApply
tries to fit arguments to a function type with/without implicit views.When the error policies entails error/warning buffering, the mutable ReportBuffer records everything that is issued. It is important to note, that child Contexts created with
make
"inherit" the very sameReportBuffer
instance, whereas children spawned throughmakeSilent
receive an separate, fresh buffer.