diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java index 4e47ba7ca74..766537f4c01 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java @@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.calls.inference.*; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; +import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeSubstitutor; import org.jetbrains.jet.lang.types.TypeUtils; @@ -376,7 +377,7 @@ public class Renderers { typeBounds.add(constraintSystem.getTypeBounds(variable)); } Function renderTypeBounds = rendererToFunction(RENDER_TYPE_BOUNDS); - return "type parameter bounds:\n" + StringUtil.join(typeBounds, renderTypeBounds, ";\n") + "\n" + + return "type parameter bounds:\n" + StringUtil.join(typeBounds, renderTypeBounds, "\n") + "\n" + "status:\n" + ConstraintsUtil.getDebugMessageForStatus(constraintSystem.getStatus()); } }; @@ -388,11 +389,15 @@ public class Renderers { Function renderBound = new Function() { @Override public String fun(TypeBoundsImpl.Bound bound) { - String arrow = bound.kind == LOWER_BOUND ? "<: " : bound.kind == UPPER_BOUND ? ">: " : "= "; - return arrow + bound.type + '(' + bound.position + ')'; + String arrow = bound.kind == LOWER_BOUND ? ">: " : bound.kind == UPPER_BOUND ? "<: " : ":= "; + return arrow + RENDER_TYPE.render(bound.type) + '(' + bound.position + ')'; } }; - return typeBounds.getTypeVariable().getName() + " " + StringUtil.join(typeBounds.getBounds(), renderBound, ", "); + Name typeVariableName = typeBounds.getTypeVariable().getName(); + if (typeBounds.isEmpty()) { + return typeVariableName.asString(); + } + return typeVariableName + " " + StringUtil.join(typeBounds.getBounds(), renderBound, ", "); } }; diff --git a/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds b/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds new file mode 100644 index 00000000000..56f29c35df1 --- /dev/null +++ b/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUBTYPE T Int +SUPERTYPE T String + +type parameter bounds: +T <: jet.Int(SPECIAL), >: jet.String(SPECIAL) +status: +-hasConflictingConstraints: true +-hasContradiction: true +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/simpleSuccessful.bounds b/compiler/testData/constraintSystem/checkStatus/successful.bounds similarity index 80% rename from compiler/testData/constraintSystem/simpleSuccessful.bounds rename to compiler/testData/constraintSystem/checkStatus/successful.bounds index d2988a81023..116033159e1 100644 --- a/compiler/testData/constraintSystem/simpleSuccessful.bounds +++ b/compiler/testData/constraintSystem/checkStatus/successful.bounds @@ -1,10 +1,10 @@ VARIABLES T SUBTYPE T Int -SUPERTYPE T Int ! +SUPERTYPE T Int type parameter bounds: -T >: Int(SPECIAL), <: Int(SPECIAL) +T <: jet.Int(SPECIAL), >: jet.Int(SPECIAL) status: -hasConflictingConstraints: false -hasContradiction: false @@ -15,4 +15,4 @@ status: -isSuccessful: true result: -T=Int +T=jet.Int diff --git a/compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.bounds b/compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.bounds new file mode 100644 index 00000000000..ccc74cf79bd --- /dev/null +++ b/compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUBTYPE List Int + +type parameter bounds: +T +status: +-hasConflictingConstraints: false +-hasContradiction: true +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: true +-hasUnknownParameters: true +-hasViolatedUpperBound: false +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/checkStatus/unknownParameters.bounds b/compiler/testData/constraintSystem/checkStatus/unknownParameters.bounds new file mode 100644 index 00000000000..9f653baf4a2 --- /dev/null +++ b/compiler/testData/constraintSystem/checkStatus/unknownParameters.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUBTYPE Any Any + +type parameter bounds: +T +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: true +-hasViolatedUpperBound: false +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds b/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds new file mode 100644 index 00000000000..244e16764cc --- /dev/null +++ b/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUBTYPE T Int +SUBTYPE T String ! + +type parameter bounds: +T <: jet.Int(SPECIAL), <: jet.String(TYPE_BOUND_POSITION(0)) +status: +-hasConflictingConstraints: true +-hasContradiction: true +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: true +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/computeValues/contradiction.bounds b/compiler/testData/constraintSystem/computeValues/contradiction.bounds new file mode 100644 index 00000000000..0f508fa78c5 --- /dev/null +++ b/compiler/testData/constraintSystem/computeValues/contradiction.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUBTYPE T B +SUPERTYPE T A + +type parameter bounds: +T <: B(SPECIAL), >: A(SPECIAL) +status: +-hasConflictingConstraints: true +-hasContradiction: true +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.bounds b/compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.bounds new file mode 100644 index 00000000000..0f8a0021f54 --- /dev/null +++ b/compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUBTYPE T A +SUBTYPE T B + +type parameter bounds: +T <: A(SPECIAL), <: B(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=B diff --git a/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.bounds b/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.bounds new file mode 100644 index 00000000000..1b632359e1b --- /dev/null +++ b/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUBTYPE T A +SUPERTYPE T C + +type parameter bounds: +T <: A(SPECIAL), >: C(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=C diff --git a/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.bounds b/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.bounds new file mode 100644 index 00000000000..57f7b650266 --- /dev/null +++ b/compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.bounds @@ -0,0 +1,19 @@ +VARIABLES T + +SUBTYPE T A +SUPERTYPE T B +SUPERTYPE T C + +type parameter bounds: +T <: A(SPECIAL), >: B(SPECIAL), >: C(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=B diff --git a/compiler/testData/constraintSystem/declarations/declarations.kt b/compiler/testData/constraintSystem/declarations/declarations.kt index dbb6e644c2b..d4dc77f5df6 100644 --- a/compiler/testData/constraintSystem/declarations/declarations.kt +++ b/compiler/testData/constraintSystem/declarations/declarations.kt @@ -1,4 +1,4 @@ -fun foo() = 42 +fun foo() = 42 trait A trait B : A diff --git a/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds b/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds new file mode 100644 index 00000000000..f539e2cda5f --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1000) +SUBTYPE T Byte + +type parameter bounds: +T >: IntegerValueType(1000)(SPECIAL), <: jet.Byte(SPECIAL) +status: +-hasConflictingConstraints: true +-hasContradiction: true +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: false + +result: +T=??? diff --git a/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds b/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds new file mode 100644 index 00000000000..b24a930adce --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(10000000000) + +type parameter bounds: +T >: IntegerValueType(10000000000)(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Long diff --git a/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds b/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds new file mode 100644 index 00000000000..8d2acd47896 --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) +SUBTYPE T Any + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL), <: jet.Any(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Int diff --git a/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds b/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds new file mode 100644 index 00000000000..6f446658e5f --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) +SUPERTYPE T String + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL), >: jet.String(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Comparable diff --git a/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds b/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds new file mode 100644 index 00000000000..da2bdf21e5a --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) +SUPERTYPE T IntegerValueType(1000) + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL), >: IntegerValueType(1000)(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Int diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds new file mode 100644 index 00000000000..ed1a435cbb7 --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) +SUBTYPE T Byte + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL), <: jet.Byte(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Byte diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds new file mode 100644 index 00000000000..2b37653950a --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Int diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds new file mode 100644 index 00000000000..4d98f4179fa --- /dev/null +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds @@ -0,0 +1,18 @@ +VARIABLES T + +SUPERTYPE T IntegerValueType(1) +SUBTYPE T Short + +type parameter bounds: +T >: IntegerValueType(1)(SPECIAL), <: jet.Short(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Short diff --git a/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds b/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds new file mode 100644 index 00000000000..a5011ef6f79 --- /dev/null +++ b/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds @@ -0,0 +1,20 @@ +VARIABLES T P + +SUBTYPE T Int + +type parameter bounds: +T <: jet.Int(SPECIAL) +P <: ???(TYPE_BOUND_POSITION(1)), <: jet.Int(COMPOUND_CONSTRAINT_POSITION) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=jet.Int +P=jet.Int + diff --git a/compiler/testData/constraintSystem/variance/consumer.bounds b/compiler/testData/constraintSystem/variance/consumer.bounds new file mode 100644 index 00000000000..466e95d745f --- /dev/null +++ b/compiler/testData/constraintSystem/variance/consumer.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUBTYPE Consumer Consumer + +type parameter bounds: +T <: A(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=A diff --git a/compiler/testData/constraintSystem/variance/invariant.bounds b/compiler/testData/constraintSystem/variance/invariant.bounds new file mode 100644 index 00000000000..41ba87c7485 --- /dev/null +++ b/compiler/testData/constraintSystem/variance/invariant.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUBTYPE My My + +type parameter bounds: +T := A(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=A diff --git a/compiler/testData/constraintSystem/variance/producer.bounds b/compiler/testData/constraintSystem/variance/producer.bounds new file mode 100644 index 00000000000..b310664e485 --- /dev/null +++ b/compiler/testData/constraintSystem/variance/producer.bounds @@ -0,0 +1,17 @@ +VARIABLES T + +SUBTYPE Producer Producer + +type parameter bounds: +T >: A(SPECIAL) +status: +-hasConflictingConstraints: false +-hasContradiction: false +-hasErrorInConstrainingTypes: false +-hasTypeConstructorMismatch: false +-hasUnknownParameters: false +-hasViolatedUpperBound: false +-isSuccessful: true + +result: +T=A diff --git a/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTest.kt b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/AbstractConstraintSystemTest.kt similarity index 85% rename from compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTest.kt rename to compiler/tests/org/jetbrains/jet/resolve/constraintSystem/AbstractConstraintSystemTest.kt index ba56fbfa253..98aa9bb44c6 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTest.kt +++ b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/AbstractConstraintSystemTest.kt @@ -46,15 +46,16 @@ import java.util.Collections import com.intellij.openapi.project.Project import java.util.HashMap import java.util.regex.Pattern -import org.jetbrains.jet.resolve.constraintSystem.ConstraintSystemTest.MyConstraintKind -import org.jetbrains.jet.resolve.constraintSystem.ConstraintSystemTest.MyConstraint +import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest.MyConstraintKind +import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest.MyConstraint import java.util.ArrayList import kotlin.test.assertEquals import org.junit.Assert +import java.util.LinkedHashMap -public class ConstraintSystemTest() : JetLiteFixture() { - - val constraintPattern = Pattern.compile("(SUBTYPE|SUPERTYPE|EQUALITY)\\s+(\\w+)\\s+(\\w+)", Pattern.MULTILINE) +abstract public class AbstractConstraintSystemTest() : JetLiteFixture() { + private val typePattern = """([\w|<|>|\(|\)]+)""" + val constraintPattern = Pattern.compile("""(SUBTYPE|SUPERTYPE|EQUALITY)\s+${typePattern}\s+${typePattern}\s+(!)?""", Pattern.MULTILINE) val variablesPattern = Pattern.compile("VARIABLES\\s+(.*)") private var builtIns: KotlinBuiltIns? = null @@ -92,10 +93,6 @@ public class ConstraintSystemTest() : JetLiteFixture() { return MyDeclarations(bindingContext, getProject(), typeResolver!!) } - public fun testSimpleSuccessful() { - doTest("compiler/testData/constraintSystem/simpleSuccessful.bounds") - } - public fun doTest(filePath: String) { val file = File(filePath) val fileText = JetTestUtils.doLoadFile(file)!! @@ -103,7 +100,7 @@ public class ConstraintSystemTest() : JetLiteFixture() { val constraintSystem = ConstraintSystemImpl() val myDeclarations = analyzeDeclarations() - val typeParameterDescriptors = HashMap() + val typeParameterDescriptors = LinkedHashMap() val variables = parseVariables(fileText) for (variable in variables) { typeParameterDescriptors.put(myDeclarations.getParameterDescriptor(variable), Variance.INVARIANT) @@ -120,20 +117,18 @@ public class ConstraintSystemTest() : JetLiteFixture() { MyConstraintKind.SUPERTYPE -> constraintSystem.addSupertypeConstraint(firstType, secondType, position) } } + constraintSystem.processDeclaredBoundConstraints() - val expectedStatus = parseStatus(fileText) val resultingStatus = Renderers.RENDER_CONSTRAINT_SYSTEM.render(constraintSystem) - Assert.assertEquals("Constraint system status mismatch", expectedStatus, resultingStatus) val resultingSubstitutor = constraintSystem.getResultingSubstitutor() val result = StringBuilder() append "result:\n" for ((typeParameter, variance) in typeParameterDescriptors) { val resultForTypeParameter = resultingSubstitutor.substitute(myDeclarations.getType(typeParameter.getName().asString()), variance) - result append "${typeParameter.getName()}=${resultForTypeParameter}" + result append "${typeParameter.getName()}=${resultForTypeParameter?.let{ Renderers.RENDER_TYPE.render(it) }}\n" } - val expectedResult = parseResult(fileText) - Assert.assertEquals("Constraint system substitution mismatch", expectedResult, result.toString()) + JetTestUtils.assertEqualsToFile(file, "${getConstraintsText(fileText)}${resultingStatus}\n\n${result}\n") } class MyConstraint(val kind: MyConstraintKind, val firstType: String, val secondType: String, val isWeak: Boolean) @@ -164,9 +159,7 @@ public class ConstraintSystemTest() : JetLiteFixture() { return constraints } - private fun parseStatus(text: String) = text.substring(text.indexOf("type parameter bounds"), text.indexOf("result")).trim() - - private fun parseResult(text: String) = text.substring(text.indexOf("result"), text.length()) + private fun getConstraintsText(text: String) = text.substring(0, text.indexOf("type parameter bounds")) } diff --git a/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTestGenerated.java b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTestGenerated.java new file mode 100644 index 00000000000..7e9ad234390 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/ConstraintSystemTestGenerated.java @@ -0,0 +1,195 @@ +/* + * Copyright 2010-2014 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.jet.resolve.constraintSystem; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import java.util.regex.Pattern; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/constraintSystem") +@InnerTestClasses({ConstraintSystemTestGenerated.CheckStatus.class, ConstraintSystemTestGenerated.ComputeValues.class, ConstraintSystemTestGenerated.IntegerValueTypes.class, ConstraintSystemTestGenerated.SeveralVariables.class, ConstraintSystemTestGenerated.Variance.class}) +public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest { + public void testAllFilesPresentInConstraintSystem() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("compiler/testData/constraintSystem/checkStatus") + public static class CheckStatus extends AbstractConstraintSystemTest { + public void testAllFilesPresentInCheckStatus() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem/checkStatus"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("conflictingConstraints.bounds") + public void testConflictingConstraints() throws Exception { + doTest("compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds"); + } + + @TestMetadata("successful.bounds") + public void testSuccessful() throws Exception { + doTest("compiler/testData/constraintSystem/checkStatus/successful.bounds"); + } + + @TestMetadata("typeConstructorMismatch.bounds") + public void testTypeConstructorMismatch() throws Exception { + doTest("compiler/testData/constraintSystem/checkStatus/typeConstructorMismatch.bounds"); + } + + @TestMetadata("unknownParameters.bounds") + public void testUnknownParameters() throws Exception { + doTest("compiler/testData/constraintSystem/checkStatus/unknownParameters.bounds"); + } + + @TestMetadata("violatedUpperBound.bounds") + public void testViolatedUpperBound() throws Exception { + doTest("compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds"); + } + + } + + @TestMetadata("compiler/testData/constraintSystem/computeValues") + public static class ComputeValues extends AbstractConstraintSystemTest { + public void testAllFilesPresentInComputeValues() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem/computeValues"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("contradiction.bounds") + public void testContradiction() throws Exception { + doTest("compiler/testData/constraintSystem/computeValues/contradiction.bounds"); + } + + @TestMetadata("subTypeOfUpperBounds.bounds") + public void testSubTypeOfUpperBounds() throws Exception { + doTest("compiler/testData/constraintSystem/computeValues/subTypeOfUpperBounds.bounds"); + } + + @TestMetadata("superTypeOfLowerBounds1.bounds") + public void testSuperTypeOfLowerBounds1() throws Exception { + doTest("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds1.bounds"); + } + + @TestMetadata("superTypeOfLowerBounds2.bounds") + public void testSuperTypeOfLowerBounds2() throws Exception { + doTest("compiler/testData/constraintSystem/computeValues/superTypeOfLowerBounds2.bounds"); + } + + } + + @TestMetadata("compiler/testData/constraintSystem/integerValueTypes") + public static class IntegerValueTypes extends AbstractConstraintSystemTest { + public void testAllFilesPresentInIntegerValueTypes() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem/integerValueTypes"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("byteOverflow.bounds") + public void testByteOverflow() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds"); + } + + @TestMetadata("defaultLong.bounds") + public void testDefaultLong() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds"); + } + + @TestMetadata("numberAndAny.bounds") + public void testNumberAndAny() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds"); + } + + @TestMetadata("numberAndString.bounds") + public void testNumberAndString() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds"); + } + + @TestMetadata("severalNumbers.bounds") + public void testSeveralNumbers() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds"); + } + + @TestMetadata("simpleByte.bounds") + public void testSimpleByte() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds"); + } + + @TestMetadata("simpleInt.bounds") + public void testSimpleInt() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds"); + } + + @TestMetadata("simpleShort.bounds") + public void testSimpleShort() throws Exception { + doTest("compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds"); + } + + } + + @TestMetadata("compiler/testData/constraintSystem/severalVariables") + public static class SeveralVariables extends AbstractConstraintSystemTest { + public void testAllFilesPresentInSeveralVariables() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem/severalVariables"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("simpleDependency.bounds") + public void testSimpleDependency() throws Exception { + doTest("compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds"); + } + + } + + @TestMetadata("compiler/testData/constraintSystem/variance") + public static class Variance extends AbstractConstraintSystemTest { + public void testAllFilesPresentInVariance() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/constraintSystem/variance"), Pattern.compile("^(.+)\\.bounds$"), true); + } + + @TestMetadata("consumer.bounds") + public void testConsumer() throws Exception { + doTest("compiler/testData/constraintSystem/variance/consumer.bounds"); + } + + @TestMetadata("invariant.bounds") + public void testInvariant() throws Exception { + doTest("compiler/testData/constraintSystem/variance/invariant.bounds"); + } + + @TestMetadata("producer.bounds") + public void testProducer() throws Exception { + doTest("compiler/testData/constraintSystem/variance/producer.bounds"); + } + + } + + public static Test suite() { + TestSuite suite = new TestSuite("ConstraintSystemTestGenerated"); + suite.addTestSuite(ConstraintSystemTestGenerated.class); + suite.addTestSuite(CheckStatus.class); + suite.addTestSuite(ComputeValues.class); + suite.addTestSuite(IntegerValueTypes.class); + suite.addTestSuite(SeveralVariables.class); + suite.addTestSuite(Variance.class); + return suite; + } +} diff --git a/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/MyDeclarations.kt b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/MyDeclarations.kt index 9dc777aef73..19c5a21fb38 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/MyDeclarations.kt +++ b/compiler/tests/org/jetbrains/jet/resolve/constraintSystem/MyDeclarations.kt @@ -44,6 +44,9 @@ import java.io.File import java.io.IOException import java.util.Collections import com.intellij.openapi.project.Project +import java.util.regex.Pattern +import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor +import org.jetbrains.jet.lang.types.JetTypeImpl public class MyDeclarations( private val context: BindingContext, @@ -70,7 +73,16 @@ public class MyDeclarations( throw AssertionError("Unsupported type parameter name: " + name + ".") } - fun getType(name: String) = typeResolver.resolveType( + fun getType(name: String): JetType { + val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name) + if (matcher.find()) { + val number = matcher.group(1)!! + return JetTypeImpl(IntegerValueTypeConstructor(number.toLong()), JetScope.EMPTY) + } + return typeResolver.resolveType( scopeToResolveTypeParameters, JetPsiFactory.createType(project, name), JetTestUtils.DUMMY_TRACE, true) + } } + +private val INTEGER_VALUE_TYPE_PATTERN = Pattern.compile("""IntegerValueType\((\d*)\)""") diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 4c4ff004020..4310239281e 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -87,6 +87,7 @@ import org.jetbrains.jet.completion.handlers.AbstractSmartCompletionHandlerTest import org.jetbrains.jet.generators.tests.generator.TestGeneratorUtil import org.jetbrains.jet.resolve.AbstractAdditionalLazyResolveDescriptorRendererTest import org.jetbrains.jet.resolve.AbstractReferenceResolveInLibrarySourcesTest +import org.jetbrains.jet.resolve.constraintSystem.AbstractConstraintSystemTest import org.jetbrains.jet.completion.AbstractCompiledKotlinInJavaCompletionTest import org.jetbrains.jet.completion.AbstractKotlinSourceInJavaCompletionTest import org.jetbrains.jet.plugin.intentions.AbstractIntentionTest @@ -117,6 +118,10 @@ fun main(args: Array) { model("resolvedCalls") } + testClass(javaClass()) { + model("constraintSystem", extension = "bounds") + } + testClass(javaClass()) { model("psi", testMethod = "doParsingTest") }