org.jetbrains.jet.lang.resolve.calls.inference
Class ConstraintSystemImpl

java.lang.Object
  extended by org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl
All Implemented Interfaces:
ConstraintSystem

public class ConstraintSystemImpl
extends java.lang.Object
implements ConstraintSystem


Nested Class Summary
static class ConstraintSystemImpl.ConstraintKind
           
 
Constructor Summary
ConstraintSystemImpl()
           
 
Method Summary
 void addSubtypeConstraint(JetType constrainingType, JetType subjectType, ConstraintPosition constraintPosition)
          Adds a constraint that the constraining type is a subtype of the subject type.

Asserts that only subject type may contain registered type variables.

 void addSupertypeConstraint(JetType constrainingType, JetType subjectType, ConstraintPosition constraintPosition)
          Adds a constraint that the constraining type is a supertype of the subject type.
 ConstraintSystem copy()
           
static JetType createCorrespondingExtensionFunctionType(JetType functionType, JetType receiverType)
           
 TypeSubstitutor getCurrentSubstitutor()
          Returns a current result of solving the constraint system (mapping from the type variable to the resulting type projection).
 TypeSubstitutor getResultingSubstitutor()
          Returns a result of solving the constraint system (mapping from the type variable to the resulting type projection).
 TypeConstraints getTypeConstraints(TypeParameterDescriptor typeVariable)
          Returns the resulting type constraints of solving the constraint system for specific type variable.
 java.util.Set<TypeParameterDescriptor> getTypeVariables()
          Returns a set of all registered type variables.
 boolean hasConflictingConstraints()
          Returns true if type constraints for some type variable are contradicting.
 boolean hasContradiction()
          Return true if constraint system has no contradiction (it can be not successful because of the lack of information for a type variable).
 boolean hasErrorInConstrainingTypes()
          Returns true if there is an error in constraining types.
 boolean hasOnlyExpectedTypeMismatch()
          Returns true if there is type constructor mismatch only in ConstraintPosition.EXPECTED_TYPE_POSITION.
 boolean hasTypeConstructorMismatch()
          Returns true if some constraint cannot be processed because of type constructor mismatch.
 boolean hasTypeConstructorMismatchAt(ConstraintPosition constraintPosition)
          Returns true if there is type constructor mismatch error at a specific constraintPosition.
 boolean hasUnknownParameters()
          Returns true if there is no information for some registered type variable.
 boolean isSuccessful()
          Returns true if constraint system has a solution (has no contradiction and has enough information to infer each registered type variable).
 void processDeclaredBoundConstraints()
           
 void registerTypeVariable(TypeParameterDescriptor typeVariable, Variance positionVariance)
          Registers a variable in a constraint system.
 ConstraintSystem replaceTypeVariables(com.google.common.base.Function<TypeParameterDescriptor,TypeParameterDescriptor> typeVariablesMap)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstraintSystemImpl

public ConstraintSystemImpl()
Method Detail

hasTypeConstructorMismatch

public boolean hasTypeConstructorMismatch()
Description copied from interface: ConstraintSystem
Returns true if some constraint cannot be processed because of type constructor mismatch. For example, for
fun <R> foo(t: List<R>) {}
in invocation foo(hashSet("s")) there is type constructor mismatch: "HashSet<String> cannot be a subtype of List<R>".

Specified by:
hasTypeConstructorMismatch in interface ConstraintSystem

hasTypeConstructorMismatchAt

public boolean hasTypeConstructorMismatchAt(@NotNull
                                            ConstraintPosition constraintPosition)
Description copied from interface: ConstraintSystem
Returns true if there is type constructor mismatch error at a specific constraintPosition. For example, for
fun <R> foo(t: List<R>) {}
in invocation foo(hashSet("s")) there is type constructor mismatch: "HashSet<String> cannot be a subtype of List<R>" at a constraint position ConstraintPosition.getValueParameterPosition(0).

Specified by:
hasTypeConstructorMismatchAt in interface ConstraintSystem

hasOnlyExpectedTypeMismatch

public boolean hasOnlyExpectedTypeMismatch()
Description copied from interface: ConstraintSystem
Returns true if there is type constructor mismatch only in ConstraintPosition.EXPECTED_TYPE_POSITION.

Specified by:
hasOnlyExpectedTypeMismatch in interface ConstraintSystem

hasErrorInConstrainingTypes

public boolean hasErrorInConstrainingTypes()
Description copied from interface: ConstraintSystem
Returns true if there is an error in constraining types.

Is used not to generate type inference error if there was one in argument types.

Specified by:
hasErrorInConstrainingTypes in interface ConstraintSystem

registerTypeVariable

public void registerTypeVariable(@NotNull
                                 TypeParameterDescriptor typeVariable,
                                 @NotNull
                                 Variance positionVariance)
Description copied from interface: ConstraintSystem
Registers a variable in a constraint system.

Specified by:
registerTypeVariable in interface ConstraintSystem

copy

@NotNull
public ConstraintSystem copy()
Specified by:
copy in interface ConstraintSystem

replaceTypeVariables

@NotNull
public ConstraintSystem replaceTypeVariables(@NotNull
                                                     com.google.common.base.Function<TypeParameterDescriptor,TypeParameterDescriptor> typeVariablesMap)

addSupertypeConstraint

public void addSupertypeConstraint(@Nullable
                                   JetType constrainingType,
                                   @NotNull
                                   JetType subjectType,
                                   @NotNull
                                   ConstraintPosition constraintPosition)
Description copied from interface: ConstraintSystem
Adds a constraint that the constraining type is a supertype of the subject type.

Asserts that only subject type may contain registered type variables.

For example, for "fun <T> create() : T" to infer T in invocation "val i: Int = create()" should be generated a constraint "Int is a supertype of T" where T is a subject type, and Int is a constraining type.

Specified by:
addSupertypeConstraint in interface ConstraintSystem

addSubtypeConstraint

public void addSubtypeConstraint(@Nullable
                                 JetType constrainingType,
                                 @NotNull
                                 JetType subjectType,
                                 @NotNull
                                 ConstraintPosition constraintPosition)
Description copied from interface: ConstraintSystem
Adds a constraint that the constraining type is a subtype of the subject type.

Asserts that only subject type may contain registered type variables.

For example, for "fun <T> id(t: T) {}" to infer T in invocation "id(1)" should be generated a constraint "Int is a subtype of T" where T is a subject type, and Int is a constraining type.

Specified by:
addSubtypeConstraint in interface ConstraintSystem

processDeclaredBoundConstraints

public void processDeclaredBoundConstraints()

getTypeVariables

@NotNull
public java.util.Set<TypeParameterDescriptor> getTypeVariables()
Description copied from interface: ConstraintSystem
Returns a set of all registered type variables.

Specified by:
getTypeVariables in interface ConstraintSystem

getTypeConstraints

@Nullable
public TypeConstraints getTypeConstraints(@NotNull
                                                   TypeParameterDescriptor typeVariable)
Description copied from interface: ConstraintSystem
Returns the resulting type constraints of solving the constraint system for specific type variable.

Returns null if the type variable was not registered.

Specified by:
getTypeConstraints in interface ConstraintSystem

isSuccessful

public boolean isSuccessful()
Description copied from interface: ConstraintSystem
Returns true if constraint system has a solution (has no contradiction and has enough information to infer each registered type variable).

Specified by:
isSuccessful in interface ConstraintSystem

hasContradiction

public boolean hasContradiction()
Description copied from interface: ConstraintSystem
Return true if constraint system has no contradiction (it can be not successful because of the lack of information for a type variable).

Specified by:
hasContradiction in interface ConstraintSystem

hasConflictingConstraints

public boolean hasConflictingConstraints()
Description copied from interface: ConstraintSystem
Returns true if type constraints for some type variable are contradicting.

For example, for

fun <R> foo(r: R, t: java.util.List<R>) {}
in invocation foo(1, arrayList("s")) type variable R has two conflicting constraints:

- "R is a supertype of Int"

- "List<R> is a supertype of List<String>" which leads to "R is equal to String"

Specified by:
hasConflictingConstraints in interface ConstraintSystem

hasUnknownParameters

public boolean hasUnknownParameters()
Description copied from interface: ConstraintSystem
Returns true if there is no information for some registered type variable. For example, for
fun <E> newList()
in invocation "val nl = newList()" there is no information to infer type variable E.

Specified by:
hasUnknownParameters in interface ConstraintSystem

getResultingSubstitutor

@NotNull
public TypeSubstitutor getResultingSubstitutor()
Description copied from interface: ConstraintSystem
Returns a result of solving the constraint system (mapping from the type variable to the resulting type projection).

In the resulting substitution should be concerned:

- type constraints

- variance of the type variable // not implemented yet

- type parameter bounds (that can bind type variables with each other). // not implemented yet If the addition of the 'expected type' constraint made the system fail, this constraint is not included in the resulting substitution.

Specified by:
getResultingSubstitutor in interface ConstraintSystem

getCurrentSubstitutor

@NotNull
public TypeSubstitutor getCurrentSubstitutor()
Description copied from interface: ConstraintSystem
Returns a current result of solving the constraint system (mapping from the type variable to the resulting type projection). If there is no information for type parameter, returns type projection for DONT_CARE type.

Specified by:
getCurrentSubstitutor in interface ConstraintSystem

createCorrespondingExtensionFunctionType

@NotNull
public static JetType createCorrespondingExtensionFunctionType(@NotNull
                                                                       JetType functionType,
                                                                       @NotNull
                                                                       JetType receiverType)