Class

scala.tools.nsc.typechecker.Contexts

Context

Related Doc: package Contexts

Permalink

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:

And behaviour:

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
Linear Supertypes
Known Subclasses
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Context
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class TryTwice extends AnyRef

    Permalink

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

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink

    Test two objects for inequality.

    Test two objects for inequality.

    returns

    true if !(this == that), false otherwise.

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink

    Equivalent to x.hashCode except for boxed numeric types and null.

    Equivalent to x.hashCode except for boxed numeric types and null. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException.

    returns

    a hash value consistent with ==

    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Permalink
    Implicit information
    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
  4. def ->[B](y: B): (Analyzer.Context, B)

    Permalink
    Implicit information
    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()
  5. final def ==(arg0: Any): Boolean

    Permalink

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    Definition Classes
    AnyRef → Any
  6. def ambiguousErrors: Boolean

    Permalink
  7. def apply(mask: ContextMode): Boolean

    Permalink

    Is this context in all modes in the given mask?

  8. final def asInstanceOf[T0]: T0

    Permalink

    Cast the receiver object to be of type T0.

    Cast the receiver object to be of type T0.

    Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expression List(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested type.

    returns

    the receiver object.

    Definition Classes
    Any
    Exceptions thrown

    ClassCastException if the receiver object is not an instance of the erasure of type T0.

  9. def bufferErrors: Boolean

    Permalink
  10. def clone(): AnyRef

    Permalink

    Create a copy of the receiver object.

    Create a copy of the receiver object.

    The default implementation of the clone method is platform dependent.

    returns

    a copy of the receiver object.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
    Note

    not specified by SLS as a member of AnyRef

  11. var contextMode: ContextMode

    Permalink

    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

  12. def defaultModeForTyped: Mode

    Permalink
  13. def deprecationWarning(pos: Global.Position, sym: Global.Symbol): Unit

    Permalink
  14. def deprecationWarning(pos: Global.Position, sym: Global.Symbol, msg: String): Unit

    Permalink
  15. val depth: Int

    Permalink
  16. var diagUsedDefaults: Boolean

    Permalink

    To enrich error messages involving default arguments.

    To enrich error messages involving default arguments. When extending the notion, group diagnostics in an object.

  17. def echo(pos: Global.Position, msg: String): Unit

    Permalink
  18. var enclClass: Analyzer.Context

    Permalink

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

  19. def enclClassOrMethod: Analyzer.Context

    Permalink

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

  20. var enclMethod: Analyzer.Context

    Permalink

    The next outer context whose tree is a method

  21. def enclosingApply: Analyzer.Context

    Permalink

    ...or an Apply.

  22. def enclosingCaseDef: Analyzer.Context

    Permalink

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

  23. def enclosingContextChain: List[Analyzer.Context]

    Permalink
  24. def enclosingNonImportContext: Analyzer.Context

    Permalink
  25. def enclosingSubClassContext(clazz: Global.Symbol): Analyzer.Context

    Permalink

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

  26. def enrichmentEnabled: Boolean

    Permalink
  27. def enrichmentEnabled_=(value: Boolean): Unit

    Permalink
  28. def ensuring(cond: (Analyzer.Context) ⇒ Boolean, msg: ⇒ Any): Analyzer.Context

    Permalink
    Implicit information
    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
  29. def ensuring(cond: (Analyzer.Context) ⇒ Boolean): Analyzer.Context

    Permalink
    Implicit information
    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
  30. def ensuring(cond: Boolean, msg: ⇒ Any): Analyzer.Context

    Permalink
    Implicit information
    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
  31. def ensuring(cond: Boolean): Analyzer.Context

    Permalink
    Implicit information
    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
  32. final def eq(arg0: AnyRef): Boolean

    Permalink

    Tests whether the argument (that) is a reference to the receiver object (this).

    Tests whether the argument (that) is a reference to the receiver object (this).

    The eq method implements an equivalence relation on non-null instances of AnyRef, and has three additional properties:

    • It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of x.eq(y) consistently returns true or consistently returns false.
    • For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.
    • null.eq(null) returns true.

    When overriding the equals or hashCode methods, it is important to ensure that their behavior is consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

    returns

    true if the argument is a reference to the receiver object; false otherwise.

    Definition Classes
    AnyRef
  33. def equals(arg0: Any): Boolean

    Permalink

    The equality method for reference types.

    The equality method for reference types. Default implementation delegates to eq.

    See also equals in scala.Any.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    Definition Classes
    AnyRef → Any
  34. def error(pos: Global.Position, msg: String): Unit

    Permalink

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

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

    Permalink

    Return and clear the undetermined type parameters

  36. def featureWarning(pos: Global.Position, featureName: String, featureDesc: String, featureTrait: Global.Symbol, construct: ⇒ String = "", required: Boolean): Unit

    Permalink
  37. def finalize(): Unit

    Permalink

    Called by the garbage collector on the receiver object when there are no more references to the object.

    Called by the garbage collector on the receiver object when there are no more references to the object.

    The details of when and if the finalize method is invoked, as well as the interaction between finalize and non-local returns and exceptions, are all platform dependent.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
    Note

    not specified by SLS as a member of AnyRef

  38. def firstImport: Option[Analyzer.ImportInfo]

    Permalink

    Equivalent to imports.headOption, but more efficient

  39. def fixPosition(pos: Global.Position): Global.Position

    Permalink
  40. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    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()
  41. final def getClass(): Class[_]

    Permalink

    A representation that corresponds to the dynamic class of the receiver object.

    A representation that corresponds to the dynamic class of the receiver object.

    The nature of the representation is platform dependent.

    returns

    a representation that corresponds to the dynamic class of the receiver object.

    Definition Classes
    AnyRef → Any
    Note

    not specified by SLS as a member of AnyRef

  42. def hashCode(): Int

    Permalink

    The hashCode method for reference types.

    The hashCode method for reference types. See hashCode in scala.Any.

    returns

    the hash code value for this object.

    Definition Classes
    AnyRef → Any
  43. def implicitsEnabled: Boolean

    Permalink
  44. def implicitsEnabled_=(value: Boolean): Unit

    Permalink
  45. def implicitss: List[List[Analyzer.ImplicitInfo]]

    Permalink
  46. def imports: List[Analyzer.ImportInfo]

    Permalink

    The currently visible imports

  47. def inConstructorSuffix: Boolean

    Permalink
  48. def inConstructorSuffix_=(value: Boolean): Unit

    Permalink
  49. def inPatAlternative: Boolean

    Permalink
  50. def inPatAlternative_=(value: Boolean): Unit

    Permalink
  51. def inReturnExpr: Boolean

    Permalink
  52. def inSecondTry: Boolean

    Permalink
  53. def inSecondTry_=(value: Boolean): Unit

    Permalink
  54. def inSelfSuperCall: Boolean

    Permalink
  55. def inSelfSuperCall_=(value: Boolean): Unit

    Permalink
  56. final def inSilentMode(expr: ⇒ Boolean): Boolean

    Permalink
    Annotations
    @inline()
  57. def inSuperInit: Boolean

    Permalink
  58. def inSuperInit_=(value: Boolean): Unit

    Permalink
  59. def inTypeConstructorAllowed: Boolean

    Permalink
  60. def initRootContext(throwing: Boolean = false, checking: Boolean = false): Unit

    Permalink

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

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

    Permalink

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

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

    Permalink

    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.

  63. final def isInstanceOf[T0]: Boolean

    Permalink

    Test whether the dynamic type of the receiver object is T0.

    Test whether the dynamic type of the receiver object is T0.

    Note that the result of the test is modulo Scala's erasure semantics. Therefore the expression 1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the specified type.

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    Definition Classes
    Any
  64. def isNameInScope(name: Global.Name): Boolean

    Permalink
  65. def isRootImport: Boolean

    Permalink
  66. def lookup(name: Global.Name, expectedOwner: Global.Symbol): Global.Symbol

    Permalink

    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

  67. def lookupSymbol(name: Global.Name, qualifies: (Global.Symbol) ⇒ Boolean): Global.NameLookup

    Permalink

    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.

  68. def macrosEnabled: Boolean

    Permalink
  69. def macrosEnabled_=(value: Boolean): Unit

    Permalink
  70. def make(tree: Global.Tree, owner: Global.Symbol, scope: Global.Scope): Analyzer.Context

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

    Permalink

    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.

  72. def makeConstructorContext: Analyzer.Context

    Permalink

    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.

  73. def makeImplicit(reportAmbiguousErrors: Boolean): Analyzer.Context

    Permalink

    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.

  74. def makeNewScope(tree: Global.Tree, owner: Global.Symbol, reporter: Analyzer.ContextReporter = this.reporter): Analyzer.Context

    Permalink

    Make a child context that represents a new nested scope

  75. def makeNonSilent(newtree: Global.Tree): Analyzer.Context

    Permalink
  76. def makeSilent(reportAmbiguousErrors: Boolean = ambiguousErrors, newtree: Global.Tree = tree): Analyzer.Context

    Permalink

    Make a child context that buffers errors and warnings into a fresh report buffer.

  77. var namedApplyBlockInfo: Option[(Global.Tree, Analyzer.NamedApplyInfo)]

    Permalink
  78. final def ne(arg0: AnyRef): Boolean

    Permalink

    Equivalent to !(this eq that).

    Equivalent to !(this eq that).

    returns

    true if the argument is not a reference to the receiver object; false otherwise.

    Definition Classes
    AnyRef
  79. def nextEnclosing(p: (Analyzer.Context) ⇒ Boolean): Analyzer.Context

    Permalink
  80. final def notify(): Unit

    Permalink

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Note

    not specified by SLS as a member of AnyRef

  81. final def notifyAll(): Unit

    Permalink

    Wakes up all threads that are waiting on the receiver object's monitor.

    Wakes up all threads that are waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Note

    not specified by SLS as a member of AnyRef

  82. var openImplicits: List[Analyzer.OpenImplicit]

    Permalink

    Types for which implicit arguments are currently searched

  83. final def outer: Analyzer.Context

    Permalink
  84. def outerDepth: Int

    Permalink
    Attributes
    protected
  85. val owner: Global.Symbol

    Permalink

    The current owner

  86. var prefix: Global.Type

    Permalink
  87. def pushTypeBounds(sym: Global.Symbol): Unit

    Permalink
  88. def reportErrors: Boolean

    Permalink
  89. def reporter: Analyzer.ContextReporter

    Permalink
  90. def resetCache(): Unit

    Permalink
  91. def restoreTypeBounds(tp: Global.Type): Global.Type

    Permalink
  92. def returnsSeen: Boolean

    Permalink
  93. def returnsSeen_=(value: Boolean): Unit

    Permalink
  94. def retyping: Boolean

    Permalink
  95. def retyping_=(value: Boolean): Unit

    Permalink
  96. var savedTypeBounds: List[(Global.Symbol, Global.Type)]

    Permalink

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

  97. def savingUndeterminedTypeParams[A](reportAmbiguous: Boolean = ambiguousErrors)(body: ⇒ A): A

    Permalink

    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?

  98. val scope: Global.Scope

    Permalink

    The current scope

  99. def set(enable: ContextMode = NOmode, disable: ContextMode = NOmode): Context.this.type

    Permalink

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

  100. def siteString: String

    Permalink
  101. def starPatterns: Boolean

    Permalink
  102. def starPatterns_=(value: Boolean): Unit

    Permalink
  103. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  104. def toString(): String

    Permalink

    Creates a String representation of this object.

    Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.

    returns

    a String representation of the object.

    Definition Classes
    Context → AnyRef → Any
  105. val tree: Global.Tree

    Permalink

    Tree associated with this context

  106. def undetparams: List[Global.Symbol]

    Permalink

    Undetermined type parameters.

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

  107. def undetparamsString: String

    Permalink
  108. def undetparams_=(ps: List[Global.Symbol]): Unit

    Permalink
  109. val unit: Global.CompilationUnit

    Permalink
  110. def update(mask: ContextMode, value: Boolean): Unit

    Permalink

    Update all modes in mask to value

  111. var variance: Variance

    Permalink

    Variance relative to enclosing class

  112. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  113. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  114. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  115. def warning(pos: Global.Position, msg: String): Unit

    Permalink

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

  116. final def withImplicitsDisabled[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  117. final def withImplicitsDisabledAllowEnrichment[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  118. final def withImplicitsEnabled[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  119. final def withMacrosDisabled[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  120. final def withMacrosEnabled[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  121. final def withMode[T](enabled: ContextMode = NOmode, disabled: ContextMode = NOmode)(op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  122. final def withOnlyStickyModes[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  123. final def withinPatAlternative[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  124. final def withinReturnExpr[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  125. final def withinSecondTry[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  126. final def withinStarPatterns[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  127. final def withinSuperInit[T](op: ⇒ T): T

    Permalink
    Annotations
    @inline()
  128. final def withinTypeConstructorAllowed[T](op: ⇒ T): T

    Permalink

    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()
  129. def [B](y: B): (Analyzer.Context, B)

    Permalink
    Implicit information
    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

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from Analyzer.Context to any2stringadd[Analyzer.Context]

Inherited by implicit conversion StringFormat from Analyzer.Context to StringFormat[Analyzer.Context]

Inherited by implicit conversion Ensuring from Analyzer.Context to Ensuring[Analyzer.Context]

Inherited by implicit conversion ArrowAssoc from Analyzer.Context to ArrowAssoc[Analyzer.Context]

Ungrouped