scala.tools.nsc.typechecker.Infer

Inferencer

class Inferencer extends AnyRef

The context-dependent inferencer part

Source
Infer.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Inferencer
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Inferencer(context: Context)

Type Members

  1. case class AccessError(tree: Tree, sym: Symbol, pre: Type, explanation: String) extends Tree with Product with Serializable

  2. abstract class SymCollector extends TypeCollector[List[Symbol]]

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. object AdjustedTypeArgs extends AnyRef

  7. def adjustTypeArgs(tparams: List[Symbol], targs: List[Type], restpe: Type = WildcardType): Result

    Retract arguments that were inferred to Nothing because inference failed.

    Retract arguments that were inferred to Nothing because inference failed. Correct types for repeated params.

    We detect Nothing-due-to-failure by only retracting a parameter if either:

    • it occurs in an invariant/contravariant position in restpe
    • restpe == WildcardType

    Retracted parameters are mapped to None. TODO:

    • make sure the performance hit of storing these in a map is acceptable (it's going to be a small map in 90% of the cases, I think)
    • refactor further up the callstack so that we don't have to do this post-factum adjustment?

    Rewrite for repeated param types: Map T* entries to Seq[T].

    returns

    map from tparams to inferred arg, if inference was successful, tparams that map to None are considered left undetermined type parameters that are inferred as scala.Nothing' and that are not covariant in restpe are taken to be undetermined

  8. object approximateAbstracts extends TypeMap

  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. def checkAccessible(tree: Tree, sym: Symbol, pre: Type, site: Tree): Tree

    Check that sym is defined and accessible as a member of tree site with type pre in current context.

    Check that sym is defined and accessible as a member of tree site with type pre in current context.

    Note: pre is not refchecked -- moreover, refchecking the resulting tree may not refcheck pre, since pre may not occur in its type (callers should wrap the result in a TypeTreeWithDeferredRefCheck)

  11. def checkBounds(pos: Position, pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type], prefix: String): Unit

    error if arguments not within bounds.

  12. def checkCheckable(pos: Position, tp: Type, kind: String): Unit

  13. def checkKindBounds(tparams: List[Symbol], targs: List[Type], pre: Type, owner: Symbol): List[String]

  14. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  15. final def eq(arg0: AnyRef): Boolean

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

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

  18. def errorTree(tree: Tree, msg: String): Tree

  19. def explainTypes(tp1: Type, tp2: Type): Unit

  20. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. object freeTypeParametersNoSkolems extends SymCollector

    A traverser to collect type parameters referred to in a type

  22. object freeTypeParamsOfTerms extends SymCollector

    A traverser to collect type parameters referred to in a type

  23. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  24. def hasExactlyNumParams(tp: Type, n: Int): Boolean

  25. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  26. def inferArgumentInstance(tree: Tree, undetparams: List[Symbol], strictPt: Type, lenientPt: Type): Unit

    Substitute free type variables undetparams' of polymorphic argument expression tree', given two prototypes strictPt', and lenientPt'.

    Substitute free type variables undetparams' of polymorphic argument expression tree', given two prototypes strictPt', and lenientPt'. strictPt' is the first attempt prototype where type parameters are left unchanged. lenientPt' is the fall-back prototype where type parameters are replaced by WildcardType's. We try to instantiate first to strictPt' and then, if this fails, to lenientPt'. If both attempts fail, an error is produced.

  27. def inferConstructorInstance(tree: Tree, undetparams: List[Symbol], pt0: Type): Unit

    Substitute free type variables undetparams of type constructor tree in pattern, given prototype pt.

    Substitute free type variables undetparams of type constructor tree in pattern, given prototype pt.

    tree

    the constuctor that needs to be instantiated

    undetparams

    the undetermined type parameters

  28. def inferExprAlternative(tree: Tree, pt: Type): Unit

    Assign tree the symbol and type of the alternative which matches prototype pt, if it exists.

    Assign tree the symbol and type of the alternative which matches prototype pt, if it exists. If several alternatives match pt', take parameterless one. If no alternative matches pt', take the parameterless one anyway.

  29. def inferExprInstance(tree: Tree, tparams: List[Symbol], pt: Type = WildcardType, treeTp0: Type = null, keepNothings: Boolean = true, useWeaklyCompatible: Boolean = false): List[Symbol]

    Infer type arguments targs for tparams of polymorphic expression in tree, given prototype pt.

    Infer type arguments targs for tparams of polymorphic expression in tree, given prototype pt.

    Substitute tparams to targs in tree, after adjustment by adjustTypeArgs, returning the type parameters that were not determined If passed, infers against specified type treeTp instead of tree.tp.

  30. def inferMethodAlternative(tree: Tree, undetparams: List[Symbol], argtpes: List[Type], pt0: Type, varArgsOnly: Boolean = false): Unit

    Assign tree the type of an alternative which is applicable to argtpes, and whose result type is compatible with pt'. If several applicable alternatives exist, drop the alternatives which use default arguments, then select the most specialized one. If no applicable alternative exists, and pt != WildcardType, try again with pt = WildcardType. Otherwise, if there is no best alternative, error.

    Assign tree the type of an alternative which is applicable to argtpes, and whose result type is compatible with pt'. If several applicable alternatives exist, drop the alternatives which use default arguments, then select the most specialized one. If no applicable alternative exists, and pt != WildcardType, try again with pt = WildcardType. Otherwise, if there is no best alternative, error.

    argtpes

    contains the argument types. If an argument is named, as "a = 3", the corresponding type is NamedType("a", Int)'. If the name of some NamedType does not exist in an alternative's parameter names, the type is replaces by Unit', i.e. the argument is treated as an assignment expression.

  31. def inferMethodInstance(fn: Tree, undetparams: List[Symbol], args: List[Tree], pt0: Type): List[Symbol]

    Substitute free type variables undetparams of application fn(args), given prototype pt.

    Substitute free type variables undetparams of application fn(args), given prototype pt.

    fn

    fn: the function that needs to be instantiated.

    undetparams

    the parameters that need to be determined

    args

    the actual arguments supplied in the call.

    returns

    The type parameters that remain uninstantiated, and that thus have not been substituted.

  32. def inferModulePattern(pat: Tree, pt: Type): Unit

  33. def inferPolyAlternatives(tree: Tree, argtypes: List[Type]): Unit

    Assign tree the type of unique polymorphic alternative with nparams as the number of type parameters, if it exists.

    Assign tree the type of unique polymorphic alternative with nparams as the number of type parameters, if it exists. If several or none such polymorphic alternatives exist, error.

    tree

    ...

  34. def inferTypedPattern(pos: Position, pattp: Type, pt0: Type): Type

  35. def instBounds(tvar: TypeVar): (Type, Type)

  36. def instantiateTypeVar(tvar: TypeVar): Unit

  37. def intersect(tp1: Type, tp2: Type): Type

    Type intersection of simple type tp1 with general type tp2.

    Type intersection of simple type tp1 with general type tp2. The result eliminates some redundancies.

  38. def isAsSpecific(ftpe1: Type, ftpe2: Type): Boolean

    Is type ftpe1 strictly more specific than type ftpe2 when both are alternatives in an overloaded function?

    Is type ftpe1 strictly more specific than type ftpe2 when both are alternatives in an overloaded function?

    ftpe1

    ...

    ftpe2

    ...

    returns

    ...

    See also

    SLS (sec:overloading-resolution)

  39. def isCoercible(tp: Type, pt: Type): Boolean

    This is overridden in the Typer.

    This is overridden in the Typer.infer with some logic, but since that's the only place in the compiler an Inferencer is ever created, I suggest this should either be abstract or have the implementation.

  40. def isCompatible(tp: Type, pt: Type): Boolean

  41. def isCompatibleArgs(tps: List[Type], pts: List[Type]): Boolean

  42. def isConservativelyCompatible(tp: Type, pt: Type): Boolean

    Like weakly compatible but don't apply any implicit conversions yet.

    Like weakly compatible but don't apply any implicit conversions yet. Used when comparing the result type of a method with its prototype.

  43. def isInProperSubClassOrObject(sym1: Symbol, sym2: Symbol): Boolean

    is symbol sym1 defined in a proper subclass of symbol sym2?

  44. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  45. def isInstantiatable(tvars: List[TypeVar]): Boolean

  46. def isPlausiblyCompatible(tp: Type, pt: Type): Boolean

  47. def isProperSubClassOrObject(sym1: Symbol, sym2: Symbol): Boolean

    Is sym1 (or its companion class in case it is a module) a subclass of sym2 (or its companion class in case it is a module)?

  48. def isStrictlyMoreSpecific(ftpe1: Type, ftpe2: Type, sym1: Symbol, sym2: Symbol): Boolean

  49. def isUnitForVarArgs(args: List[AnyRef], params: List[Symbol]): Boolean

    don't do a () to (()) conversion for methods whose second parameter is a varargs.

    don't do a () to (()) conversion for methods whose second parameter is a varargs. This is a fairly kludgey way to address #3224. We'll probably find a better way to do this by identifying tupled and n-ary methods, but thiws is something for a future major revision.

  50. def isWeaklyCompatible(tp: Type, pt: Type): Boolean

  51. def makeFullyDefined(tp: Type): Type

    Replace any (possibly bounded) wildcard types in type tp by existentially bound variables.

  52. def methTypeArgs(tparams: List[Symbol], formals: List[Type], restpe: Type, argtpes: List[Type], pt: Type): Result

    Return inferred type arguments, given type parameters, formal parameters, argument types, result type and expected result type.

    Return inferred type arguments, given type parameters, formal parameters, argument types, result type and expected result type. If this is not possible, throw a NoInstance exception. Undetermined type arguments are represented by definitions.NothingClass.tpe'. No check that inferred parameters conform to their bounds is made here.

    tparams

    the type parameters of the method

    formals

    the value parameter types of the method

    argtpes

    the argument types of the application

    pt

    the expected return type of the application

    returns

    @see adjustTypeArgs

    Exceptions thrown
    NoInstance

  53. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  54. def normSubType(tp: Type, pt: Type): Boolean

  55. final def notify(): Unit

    Definition Classes
    AnyRef
  56. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  57. def protoTypeArgs(tparams: List[Symbol], formals: List[Type], restpe: Type, pt: Type): List[Type]

    Return inferred proto-type arguments of function, given its type and value parameters and result type, and a prototype pt for the function result.

    Return inferred proto-type arguments of function, given its type and value parameters and result type, and a prototype pt for the function result. Type arguments need to be either determined precisely by the prototype, or they are maximized, if they occur only covariantly in the value parameter list. If instantiation of a type parameter fails, take WildcardType for the proto-type argument.

    tparams

    ...

    formals

    ...

    pt

    ...

    returns

    ...

  58. def setError[T <: Tree](tree: T): T

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

    Definition Classes
    AnyRef
  60. object toOrigin extends TypeMap

  61. def toString(): String

    Definition Classes
    AnyRef → Any
  62. def tryTwice(infer: ⇒ Unit): Unit

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

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

    infer

    ...

  63. def typeError(pos: Position, found: Type, req: Type): Unit

  64. def typeErrorMsg(found: Type, req: Type): String

  65. def typeErrorTree(tree: Tree, found: Type, req: Type): Tree

  66. object typeRefs extends SymCollector

  67. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()
  70. def widen(tp: Type): Type

    Type with all top-level occurrences of abstract types replaced by their bounds

Inherited from AnyRef

Inherited from Any