org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.inference
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition
public trait ConstraintSystem {
/**
* Registers variables in a constraint system.
*/
public fun registerTypeVariables(typeVariables: Map)
/**
* Returns a set of all registered type variables.
*/
public fun getTypeVariables(): Set
/**
* 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 {@code "fun 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.
*/
public fun addSubtypeConstraint(constrainingType: JetType?, subjectType: JetType, constraintPosition: ConstraintPosition)
/**
* 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 {@code "fun 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.
*/
public fun addSupertypeConstraint(constrainingType: JetType?, subjectType: JetType, constraintPosition: ConstraintPosition)
public fun getStatus(): ConstraintSystemStatus
/**
* Returns the resulting type constraints of solving the constraint system for specific type variable.
* Throws IllegalArgumentException if the type variable was not registered.
*/
public fun getTypeBounds(typeVariable: TypeParameterDescriptor): TypeBounds
/**
* 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.
*/
public fun getResultingSubstitutor(): TypeSubstitutor
/**
* 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.
*/
public fun getCurrentSubstitutor(): TypeSubstitutor
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy