class Context extends AnyRef
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:
- A tree, symbol, and scope representing the focus of the typechecker
- An enclosing context,
outer
. - The current compilation unit.
- A variety of bits that track the current error reporting policy (more on this later);
whether or not implicits/macros are enabled, whether we are in a self or super call or
in a constructor suffix. These are represented as bits in the mask
contextMode
. - Some odds and ends: undetermined type parameters of the current line of type inference; contextual augmentation for error messages, tracking of the nesting depth.
And behaviour:
- The central point for issuing errors and warnings from the typechecker, with a means to buffer these for use in 'silent' type checking, when some recovery might be possible.
-
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 definitions (implicitss
) Supporting these areimports
, which represents allImport
trees in in the enclosing context chain. - In a similar vein, we can assess accessibility (
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
.
Initially, starting from the typer
phase, the contexts either buffer or report errors;
afterwards errors are thrown. This is configured in rootContext
. Additionally, more
fine grained control is needed based on the kind of error; ambiguity errors are often
suppressed during exploratory typing, such as determining whether a == b
in an argument
position is an assignment or a named argument, when Inferencer#isApplicableSafe
type checks
applications with and without an expected type, or when Typer#tryTypedApply
tries to fit arguments to
a function type with/without implicit views.
When the error policies entail 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 same ReportBuffer
instance, whereas children spawned through makeSilent
receive a separate, fresh buffer.
- Source
- Contexts.scala
- Alphabetic
- By Inheritance
- Context
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Type Members
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to any2stringadd[Analyzer.Context] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): (Analyzer.Context, B)
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to ArrowAssoc[Analyzer.Context] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def ambiguousErrors: Boolean
-
def
apply(mask: ContextMode): Boolean
Is this context in all modes in the given
mask
? -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def bufferErrors: Boolean
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
var
contextMode: ContextMode
A bitmask containing all the boolean flags in a context, e.g.
A bitmask containing all the boolean flags in a context, e.g. are implicit views enabled
- def defaultModeForTyped: Mode
- def deprecationWarning(pos: Global.Position, sym: Global.Symbol): Unit
- def deprecationWarning(pos: Global.Position, sym: Global.Symbol, msg: String, since: String): Unit
- val depth: Int
-
var
diagUsedDefaults: Boolean
To enrich error messages involving default arguments.
To enrich error messages involving default arguments. When extending the notion, group diagnostics in an object.
- def echo(pos: Global.Position, msg: String): Unit
-
var
enclClass: Analyzer.Context
The next outer context whose tree is a template or package definition
-
def
enclClassOrMethod: Analyzer.Context
The next enclosing context (potentially
this
) that is owned by a class or method -
var
enclMethod: Analyzer.Context
The next (logical) outer context whose tree is a method.
The next (logical) outer context whose tree is a method.
NOTE: this is the "logical" enclosing method, which may not be the actual enclosing method when we synthesize a nested method, such as for lazy val getters (scala/bug#8245) or the methods that implement a PartialFunction literal (scala/bug#10291).
-
def
enclosingApply: Analyzer.Context
...or an Apply.
-
def
enclosingCaseDef: Analyzer.Context
The next enclosing context (potentially
this
) that has aCaseDef
as a tree - def enclosingContextChain: List[Analyzer.Context]
-
final
def
enclosingImport: Analyzer.Context
- Annotations
- @tailrec()
- def enclosingNonImportContext: Analyzer.Context
-
def
enclosingSubClassContext(clazz: Global.Symbol): Analyzer.Context
Return the closest enclosing context that defines a subclass of
clazz
or a companion object thereof, orNoContext
if no such context exists. - def enrichmentEnabled: Boolean
- def enrichmentEnabled_=(value: Boolean): Unit
-
def
ensuring(cond: (Analyzer.Context) ⇒ Boolean, msg: ⇒ Any): Analyzer.Context
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to Ensuring[Analyzer.Context] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (Analyzer.Context) ⇒ Boolean): Analyzer.Context
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to Ensuring[Analyzer.Context] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): Analyzer.Context
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to Ensuring[Analyzer.Context] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): Analyzer.Context
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to Ensuring[Analyzer.Context] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
error(pos: Global.Position, msg: String): Unit
Issue/throw the given error message according to the current mode for error reporting.
-
def
extractUndetparams(): List[Global.Symbol]
Return and clear the undetermined type parameters
- def featureWarning(pos: Global.Position, featureName: String, featureDesc: String, featureTrait: Global.Symbol, construct: ⇒ String = "", required: Boolean): Unit
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
firstImport: Option[Analyzer.ImportInfo]
Equivalent to
imports.headOption
, but more efficient - def fixPosition(pos: Global.Position): Global.Position
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to StringFormat[Analyzer.Context] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def implicitsEnabled: Boolean
- def implicitsEnabled_=(value: Boolean): Unit
- def implicitss: List[List[Analyzer.ImplicitInfo]]
-
def
importOrNull: Analyzer.ImportInfo
- Attributes
- protected[Contexts]
-
def
imports: List[Analyzer.ImportInfo]
The currently visible imports, from innermost to outermost.
- def inConstructorSuffix: Boolean
- def inConstructorSuffix_=(value: Boolean): Unit
- def inPatAlternative: Boolean
- def inPatAlternative_=(value: Boolean): Unit
- def inReturnExpr: Boolean
- def inSecondTry: Boolean
- def inSecondTry_=(value: Boolean): Unit
- def inSelfSuperCall: Boolean
- def inSelfSuperCall_=(value: Boolean): Unit
-
final
def
inSilentMode(expr: ⇒ Boolean): Boolean
- Annotations
- @inline()
- def inSuperInit: Boolean
- def inSuperInit_=(value: Boolean): Unit
- def inTypeConstructorAllowed: Boolean
-
def
initRootContext(throwing: Boolean = false, checking: Boolean = false): Unit
Use reporter (possibly buffered) for errors/warnings and enable implicit conversion *
-
def
isAccessible(sym: Global.Symbol, pre: Global.Type, superAccess: Boolean = false): Boolean
Is
sym
accessible as a member ofpre
in current context? -
def
isInPackageObject(sym: Global.Symbol, pkg: Global.Symbol): Boolean
Must
sym
defined in package object of packagepkg
, if it selected from a prefix withpkg
as its type symbol? -
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isNameInScope(name: Global.Name): Boolean
-
def
isRootImport: Boolean
A root import is never unused and always bumps context depth.
A root import is never unused and always bumps context depth. (e.g scala._ / Predef._ and magic REPL imports)
- final def isSearchingForImplicitParam: Boolean
- final def javaFindMember(pre: Global.Type, name: Global.Name, qualifies: (Global.Symbol) ⇒ Boolean): (Global.Type, Global.Symbol)
- final def lookupCompanionInIncompleteOwner(original: Global.Symbol): Global.Symbol
- final def lookupSibling(original: Global.Symbol, name: Global.Name): Global.Symbol
- def lookupSymbol(name: Global.Name, qualifies: (Global.Symbol) ⇒ Boolean): Global.NameLookup
- def macrosEnabled: Boolean
- def macrosEnabled_=(value: Boolean): Unit
- def make(tree: Global.Tree, owner: Global.Symbol, scope: Global.Scope): Analyzer.Context
-
def
make(tree: Global.Tree = tree, owner: Global.Symbol = owner, scope: Global.Scope = scope, unit: Global.CompilationUnit = unit, reporter: Analyzer.ContextReporter = this.reporter): Analyzer.Context
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 anImport
, that import will be available at the head ofContext#imports
. -
def
makeConstructorContext: Analyzer.Context
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. -
def
makeImplicit(reportAmbiguousErrors: Boolean): Analyzer.Context
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.
-
def
makeNewScope(tree: Global.Tree, owner: Global.Symbol, reporter: Analyzer.ContextReporter = this.reporter): Analyzer.Context
Make a child context that represents a new nested scope
- def makeNonSilent(newtree: Global.Tree): Analyzer.Context
-
def
makeSilent(reportAmbiguousErrors: Boolean = ambiguousErrors, newtree: Global.Tree = tree): Analyzer.Context
Make a child context that buffers errors and warnings into a fresh report buffer.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def nextEnclosing(p: (Analyzer.Context) ⇒ Boolean): Analyzer.Context
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
var
openImplicits: List[Analyzer.OpenImplicit]
Types for which implicit arguments are currently searched
- final def outer: Analyzer.Context
-
def
outerDepth: Int
- Attributes
- protected
- final def outermostContextAtCurrentPos: Analyzer.Context
- val owner: Global.Symbol
- var prefix: Global.Type
- def pushTypeBounds(sym: Global.Symbol): Unit
- def reportErrors: Boolean
- def reporter: Analyzer.ContextReporter
- def resetCache(): Unit
- def restoreTypeBounds(tp: Global.Type): Global.Type
- def returnsSeen: Boolean
- def returnsSeen_=(value: Boolean): Unit
- def retyping: Boolean
- def retyping_=(value: Boolean): Unit
-
var
savedTypeBounds: List[(Global.Symbol, Global.Type)]
Saved type bounds for type parameters which are narrowed in a GADT.
-
def
savingUndeterminedTypeParams[A](reportAmbiguous: Boolean = ambiguousErrors)(body: ⇒ A): A
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.- reportAmbiguous
Should ambiguous errors be reported during evaluation of
body
?
- val scope: Global.Scope
-
def
set(enable: ContextMode = NOmode, disable: ContextMode = NOmode): Context.this.type
Set all modes in the mask
enable
to true, and all indisable
to false. - def siteString: String
- def starPatterns: Boolean
- def starPatterns_=(value: Boolean): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- Context → AnyRef → Any
- val tree: Global.Tree
-
def
undetparams: List[Global.Symbol]
Undetermined type parameters.
Undetermined type parameters. See
Infer#{inferExprInstance, adjustTypeArgs}
. Not inherited to child contexts - def undetparamsString: String
- def undetparams_=(ps: List[Global.Symbol]): Unit
- val unit: Global.CompilationUnit
-
def
update(mask: ContextMode, value: Boolean): Unit
Update all modes in
mask
tovalue
-
var
variance: Variance
Variance relative to enclosing class
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- def warning(pos: Global.Position, msg: String, category: WarningCategory, site: Global.Symbol): Unit
-
def
warning(pos: Global.Position, msg: String, category: WarningCategory): Unit
Issue/throw the given error message according to the current mode for error reporting.
-
final
def
withImplicits[T](enabled: Boolean)(op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withImplicitsDisabled[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withImplicitsDisabledAllowEnrichment[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withImplicitsEnabled[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withMacros[T](enabled: Boolean)(op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withMacrosDisabled[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withMacrosEnabled[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withMode[T](enabled: ContextMode = NOmode, disabled: ContextMode = NOmode)(op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withOnlyStickyModes[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withSuppressDeadArgWarning[T](suppress: Boolean)(op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinPatAlternative[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinReturnExpr[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinSecondTry[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinStarPatterns[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinSuperInit[T](op: ⇒ T): T
- Annotations
- @inline()
-
final
def
withinTypeConstructorAllowed[T](op: ⇒ T): T
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.
- Annotations
- @inline()
-
def
→[B](y: B): (Analyzer.Context, B)
- Implicit
- This member is added by an implicit conversion from Analyzer.Context to ArrowAssoc[Analyzer.Context] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
The Scala compiler and reflection APIs.