001 /*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.jet.lang.resolve.calls.inference;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
022 import org.jetbrains.jet.lang.types.JetType;
023 import org.jetbrains.jet.lang.types.TypeSubstitutor;
024
025 public interface ConstraintSystemStatus {
026 /**
027 * Returns <tt>true</tt> if constraint system has a solution (has no contradiction and has enough information to infer each registered type variable).
028 */
029 boolean isSuccessful();
030
031 /**
032 * Return <tt>true</tt> if constraint system has no contradiction (it can be not successful because of the lack of information for a type variable).
033 */
034 boolean hasContradiction();
035
036 /**
037 * Returns <tt>true</tt> if type constraints for some type variable are contradicting. <p/>
038 *
039 * For example, for <pre>fun <R> foo(r: R, t: java.util.List<R>) {}</pre> in invocation <tt>foo(1, arrayList("s"))</tt>
040 * type variable <tt>R</tt> has two conflicting constraints: <p/>
041 * - <tt>"R is a supertype of Int"</tt> <p/>
042 * - <tt>"List<R> is a supertype of List<String>"</tt> which leads to <tt>"R is equal to String"</tt>
043 */
044 boolean hasConflictingConstraints();
045
046 /**
047 * Returns <tt>true</tt> if contradiction of type constraints comes from declared bounds for type parameters.
048 *
049 * For example, for <pre>fun <R: Any> foo(r: R) {}</pre> in invocation <tt>foo(null)</tt>
050 * upper bounds <tt>Any</tt> for type parameter <tt>R</tt> is violated. <p/>
051 *
052 * It's the special case of 'hasConflictingConstraints' case.
053 */
054 boolean hasViolatedUpperBound();
055
056 /**
057 * Returns <tt>true</tt> if there is no information for some registered type variable.
058 *
059 * For example, for <pre>fun <E> newList()</pre> in invocation <tt>"val nl = newList()"</tt>
060 * there is no information to infer type variable <tt>E</tt>.
061 */
062 boolean hasUnknownParameters();
063
064 /**
065 * Returns <tt>true</tt> if some constraint cannot be processed because of type constructor mismatch.
066 *
067 * For example, for <pre>fun <R> foo(t: List<R>) {}</pre> in invocation <tt>foo(hashSet("s"))</tt>
068 * there is type constructor mismatch: <tt>"HashSet<String> cannot be a subtype of List<R>"</tt>.
069 */
070 boolean hasTypeConstructorMismatch();
071
072 /**
073 * Returns <tt>true</tt> if there is type constructor mismatch error at a specific {@code constraintPosition}.
074 *
075 * For example, for <pre>fun <R> foo(t: List<R>) {}</pre> in invocation <tt>foo(hashSet("s"))</tt>
076 * there is type constructor mismatch: <tt>"HashSet<String> cannot be a subtype of List<R>"</tt>
077 * at a constraint position {@code ConstraintPosition.getValueParameterPosition(0)}.
078 */
079 boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition);
080
081 /**
082 * Returns <tt>true</tt> if there is type constructor mismatch only in constraintPosition or
083 * constraint system is successful without constraints from this position.
084 */
085 boolean hasOnlyErrorsFromPosition(ConstraintPosition constraintPosition);
086
087 /**
088 * Returns <tt>true</tt> if there is an error in constraining types. <p/>
089 * Is used not to generate type inference error if there was one in argument types.
090 */
091 boolean hasErrorInConstrainingTypes();
092 }