Packages

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: it enclosingContextChain 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 are imports, which represents all Import 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.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Context
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class TryTwice extends AnyRef

    Try inference twice: once without views and once with views, unless views are already disabled.

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def ambiguousErrors: Boolean
  5. def apply(mask: ContextMode): Boolean

    Is this context in all modes in the given mask?

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def bufferErrors: Boolean
  8. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  9. 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

  10. def defaultModeForTyped: Mode
  11. def deprecationWarning(pos: Global.Position, sym: Global.Symbol): Unit
  12. def deprecationWarning(pos: Global.Position, sym: Global.Symbol, msg: String, since: String): Unit
  13. val depth: Int
  14. 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.

  15. def echo(pos: Global.Position, msg: String): Unit
  16. var enclClass: Analyzer.Context

    The next outer context whose tree is a template or package definition

  17. def enclClassOrMethod: Analyzer.Context

    The next enclosing context (potentially this) that is owned by a class or method

  18. 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).

  19. def enclosingApply: Analyzer.Context

    ...or an Apply.

  20. def enclosingCaseDef: Analyzer.Context

    The next enclosing context (potentially this) that has a CaseDef as a tree

  21. def enclosingContextChain: List[Analyzer.Context]
  22. final def enclosingImport: Analyzer.Context
    Annotations
    @tailrec()
  23. def enclosingNonImportContext: Analyzer.Context
  24. def enclosingSubClassContext(clazz: Global.Symbol): Analyzer.Context

    Return the closest enclosing context that defines a subclass of clazz or a companion object thereof, or NoContext if no such context exists.

  25. def enrichmentEnabled: Boolean
  26. def enrichmentEnabled_=(value: Boolean): Unit
  27. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  28. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  29. def error(pos: Global.Position, msg: String): Unit

    Issue/throw the given error message according to the current mode for error reporting.

  30. def extractUndetparams(): List[Global.Symbol]

    Return and clear the undetermined type parameters

  31. def featureWarning(pos: Global.Position, featureName: String, featureDesc: String, featureTrait: Global.Symbol, construct: ⇒ String = "", required: Boolean): Unit
  32. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  33. def firstImport: Option[Analyzer.ImportInfo]

    Equivalent to imports.headOption, but more efficient

  34. def fixPosition(pos: Global.Position): Global.Position
  35. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  36. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  37. def implicitsEnabled: Boolean
  38. def implicitsEnabled_=(value: Boolean): Unit
  39. def implicitss: List[List[Analyzer.ImplicitInfo]]
  40. def importOrNull: Analyzer.ImportInfo
  41. def imports: List[Analyzer.ImportInfo]

    The currently visible imports

  42. def inConstructorSuffix: Boolean
  43. def inConstructorSuffix_=(value: Boolean): Unit
  44. def inPatAlternative: Boolean
  45. def inPatAlternative_=(value: Boolean): Unit
  46. def inReturnExpr: Boolean
  47. def inSecondTry: Boolean
  48. def inSecondTry_=(value: Boolean): Unit
  49. def inSelfSuperCall: Boolean
  50. def inSelfSuperCall_=(value: Boolean): Unit
  51. final def inSilentMode(expr: ⇒ Boolean): Boolean
    Annotations
    @inline()
  52. def inSuperInit: Boolean
  53. def inSuperInit_=(value: Boolean): Unit
  54. def inTypeConstructorAllowed: Boolean
  55. def initRootContext(throwing: Boolean = false, checking: Boolean = false): Unit

    Use reporter (possibly buffered) for errors/warnings and enable implicit conversion *

  56. def isAccessible(sym: Global.Symbol, pre: Global.Type, superAccess: Boolean = false): Boolean

    Is sym accessible as a member of pre in current context?

  57. def isInPackageObject(sym: Global.Symbol, pkg: Global.Symbol): Boolean

    Must sym defined in package object of package pkg, if it selected from a prefix with pkg as its type symbol?

  58. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  59. def isNameInScope(name: Global.Name): Boolean
  60. def isRootImport: Boolean
  61. final def isSearchingForImplicitParam: Boolean
  62. final def lookupCompanionInIncompleteOwner(original: Global.Symbol): Global.Symbol
  63. final def lookupSibling(original: Global.Symbol, name: Global.Name): Global.Symbol
  64. def lookupSymbol(name: Global.Name, qualifies: (Global.Symbol) ⇒ Boolean): Global.NameLookup

    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.

  65. def macrosEnabled: Boolean
  66. def macrosEnabled_=(value: Boolean): Unit
  67. def make(tree: Global.Tree, owner: Global.Symbol, scope: Global.Scope): Analyzer.Context
  68. 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 an Import, that import will be available at the head of Context#imports.

  69. 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.

  70. 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.

  71. 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

  72. def makeNonSilent(newtree: Global.Tree): Analyzer.Context
  73. 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.

  74. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  75. def nextEnclosing(p: (Analyzer.Context) ⇒ Boolean): Analyzer.Context
  76. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  77. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  78. var openImplicits: List[Analyzer.OpenImplicit]

    Types for which implicit arguments are currently searched

  79. final def outer: Analyzer.Context
  80. def outerDepth: Int
    Attributes
    protected
  81. final def outermostContextAtCurrentPos: Analyzer.Context
  82. val owner: Global.Symbol
  83. var prefix: Global.Type
  84. def pushTypeBounds(sym: Global.Symbol): Unit
  85. def reportErrors: Boolean
  86. def reporter: Analyzer.ContextReporter
  87. def resetCache(): Unit
  88. def restoreTypeBounds(tp: Global.Type): Global.Type
  89. def returnsSeen: Boolean
  90. def returnsSeen_=(value: Boolean): Unit
  91. def retyping: Boolean
  92. def retyping_=(value: Boolean): Unit
  93. var savedTypeBounds: List[(Global.Symbol, Global.Type)]

    Saved type bounds for type parameters which are narrowed in a GADT.

  94. 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?

  95. val scope: Global.Scope
  96. def set(enable: ContextMode = NOmode, disable: ContextMode = NOmode): Context.this.type

    Set all modes in the mask enable to true, and all in disable to false.

  97. def siteString: String
  98. def starPatterns: Boolean
  99. def starPatterns_=(value: Boolean): Unit
  100. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  101. def toString(): String
    Definition Classes
    Context → AnyRef → Any
  102. val tree: Global.Tree
  103. def undetparams: List[Global.Symbol]

    Undetermined type parameters.

    Undetermined type parameters. See Infer#{inferExprInstance, adjustTypeArgs}. Not inherited to child contexts

  104. def undetparamsString: String
  105. def undetparams_=(ps: List[Global.Symbol]): Unit
  106. val unit: Global.CompilationUnit
  107. def update(mask: ContextMode, value: Boolean): Unit

    Update all modes in mask to value

  108. var variance: Variance

    Variance relative to enclosing class

  109. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  110. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  111. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  112. def warning(pos: Global.Position, msg: String): Unit

    Issue/throw the given error message according to the current mode for error reporting.

  113. final def withImplicits[T](enabled: Boolean)(op: ⇒ T): T
    Annotations
    @inline()
  114. final def withImplicitsDisabled[T](op: ⇒ T): T
    Annotations
    @inline()
  115. final def withImplicitsDisabledAllowEnrichment[T](op: ⇒ T): T
    Annotations
    @inline()
  116. final def withImplicitsEnabled[T](op: ⇒ T): T
    Annotations
    @inline()
  117. final def withMacros[T](enabled: Boolean)(op: ⇒ T): T
    Annotations
    @inline()
  118. final def withMacrosDisabled[T](op: ⇒ T): T
    Annotations
    @inline()
  119. final def withMacrosEnabled[T](op: ⇒ T): T
    Annotations
    @inline()
  120. final def withMode[T](enabled: ContextMode = NOmode, disabled: ContextMode = NOmode)(op: ⇒ T): T
    Annotations
    @inline()
  121. final def withOnlyStickyModes[T](op: ⇒ T): T
    Annotations
    @inline()
  122. final def withSuppressDeadArgWarning[T](suppress: Boolean)(op: ⇒ T): T
    Annotations
    @inline()
  123. final def withinPatAlternative[T](op: ⇒ T): T
    Annotations
    @inline()
  124. final def withinReturnExpr[T](op: ⇒ T): T
    Annotations
    @inline()
  125. final def withinSecondTry[T](op: ⇒ T): T
    Annotations
    @inline()
  126. final def withinStarPatterns[T](op: ⇒ T): T
    Annotations
    @inline()
  127. final def withinSuperInit[T](op: ⇒ T): T
    Annotations
    @inline()
  128. 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()

Inherited from AnyRef

Inherited from Any

Ungrouped