From d43242e74142e4ab0bd80bae0bd6e6d30aeef2da Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 15 Sep 2011 23:20:00 +0400 Subject: [PATCH] PsiChecker tests converted for new error framework --- .../jet/checkers/CheckerTestUtil.java | 9 + .../checkerWithErrorTypes/full/Abstract.jet | 241 +++++++++++++++ .../full/AnonymousInitializers.jet | 34 +++ .../full/BinaryCallsOnNullableValues.jet | 41 +++ .../checkerWithErrorTypes/full/Bounds.jet | 40 +++ .../full/BreakContinue.jet | 28 ++ .../checkerWithErrorTypes/full/Builders.jet | 121 ++++++++ .../checkerWithErrorTypes/full/Casts.jet | 16 + .../full/ClassObjects.jet | 30 ++ .../checkerWithErrorTypes/full/Constants.jet | 8 + .../full/CyclicHierarchy.jet | 30 ++ .../checkerWithErrorTypes/full/Enums.jet | 10 + .../full/ExtensionFunctions.jet | 71 +++++ .../full/ForRangeConventions.jet | 81 +++++ .../full/FunctionReturnTypes.jet | 166 +++++++++++ .../full/GenericArgumentConsistency.jet | 42 +++ .../checkerWithErrorTypes/full/IncDec.jet | 46 +++ .../full/IsExpressions.jet | 7 + .../full/MultipleBounds.jet | 72 +++++ .../full/NamespaceAsExpression.jet | 8 + .../full/NamespaceQualified.jet | 63 ++++ .../full/Nullability.jet | 280 ++++++++++++++++++ .../checkerWithErrorTypes/full/Objects.jet | 83 ++++++ .../checkerWithErrorTypes/full/Override.jet | 76 +++++ .../full/PrimaryConstructors.jet | 14 + .../full/ProjectionsInSupertypes.jet | 6 + .../checkerWithErrorTypes/full/Properties.jet | 28 ++ .../full/QualifiedExpressions.jet | 11 + .../full/QualifiedThis.jet | 41 +++ .../full/RecursiveTypeInference.jet | 42 +++ .../full/ResolveToJava.jet | 52 ++++ .../full/StringTemplates.jet | 21 ++ .../full/SupertypeListChecks.jet | 51 ++++ .../full/TraitSupertypeList.jet | 11 + .../full/UnreachableCode.jet | 161 ++++++++++ .../checkerWithErrorTypes/full/Unresolved.jet | 30 ++ .../checkerWithErrorTypes/full/Variance.jet | 40 +++ .../checkerWithErrorTypes/full/When.jet | 61 ++++ .../AmbiguityOnLazyTypeComputation.jet | 12 + .../regression/AssignmentsUnderOperators.jet | 6 + .../full/regression/CoercionToUnit.jet | 9 + .../full/regression/DoubleDefine.jet | 66 +++++ .../full/regression/Jet121.jet | 14 + .../full/regression/Jet124.jet | 8 + .../full/regression/Jet169.jet | 8 + .../full/regression/Jet17.jet | 6 + .../full/regression/Jet183-1.jet | 21 ++ .../full/regression/Jet183.jet | 22 ++ .../full/regression/Jet53.jet | 4 + .../full/regression/Jet67.jet | 4 + .../full/regression/Jet68.jet | 11 + .../full/regression/Jet69.jet | 10 + .../full/regression/Jet72.jet | 17 ++ .../full/regression/Jet81.jet | 22 ++ .../full/regression/OverrideResolution.jet | 16 + .../ScopeForSecondaryConstructors.jet | 18 ++ .../regression/SpecififcityByReceiver.jet | 9 + .../ThisConstructorInGenericClass.jet | 3 + .../regression/WrongTraceInCallResolver.jet | 9 + .../full/regression/kt251.jet | 33 +++ .../full/regression/kt303.jet | 11 + .../checkerWithErrorTypes/quick/Abstract.jet | 2 +- .../quick/AnonymousInitializers.jet | 34 +++ .../quick/BinaryCallsOnNullableValues.jet | 41 +++ .../checkerWithErrorTypes/quick/Bounds.jet | 40 +++ .../quick/BreakContinue.jet | 28 ++ .../checkerWithErrorTypes/quick/Builders.jet | 121 ++++++++ .../checkerWithErrorTypes/quick/Casts.jet | 16 + .../quick/ClassObjects.jet | 30 ++ .../checkerWithErrorTypes/quick/Constants.jet | 8 + .../quick/CyclicHierarchy.jet | 30 ++ .../checkerWithErrorTypes/quick/Enums.jet | 10 + .../quick/ExtensionFunctions.jet | 71 +++++ .../quick/ForRangeConventions.jet | 80 +++++ .../quick/FunctionReturnTypes.jet | 166 +++++++++++ .../quick/GenericArgumentConsistency.jet | 42 +++ .../checkerWithErrorTypes/quick/IncDec.jet | 46 +++ .../quick/IsExpressions.jet | 7 + .../quick/MultipleBounds.jet | 72 +++++ .../quick/NamespaceAsExpression.jet | 8 + .../quick/NamespaceQualified.jet | 63 ++++ .../quick/Nullability.jet | 280 ++++++++++++++++++ .../checkerWithErrorTypes/quick/Objects.jet | 83 ++++++ .../checkerWithErrorTypes/quick/Override.jet | 76 +++++ .../quick/PrimaryConstructors.jet | 14 + .../quick/ProjectionsInSupertypes.jet | 6 + .../quick/Properties.jet | 28 ++ .../quick/QualifiedExpressions.jet | 11 + .../quick/QualifiedThis.jet | 41 +++ .../quick/RecursiveTypeInference.jet | 42 +++ .../quick/ResolveToJava.jet | 52 ++++ .../quick/StringTemplates.jet | 21 ++ .../quick/SupertypeListChecks.jet | 50 ++++ .../quick/TraitSupertypeList.jet | 11 + .../quick/UnreachableCode.jet | 161 ++++++++++ .../quick/Unresolved.jet | 30 ++ .../checkerWithErrorTypes/quick/Variance.jet | 40 +++ .../checkerWithErrorTypes/quick/When.jet | 61 ++++ .../AmbiguityOnLazyTypeComputation.jet | 12 + .../regression/AssignmentsUnderOperators.jet | 6 + .../quick/regression/CoercionToUnit.jet | 9 + .../quick/regression/DoubleDefine.jet | 66 +++++ .../quick/regression/Jet121.jet | 14 + .../quick/regression/Jet124.jet | 8 + .../quick/regression/Jet169.jet | 8 + .../quick/regression/Jet17.jet | 6 + .../quick/regression/Jet183-1.jet | 21 ++ .../quick/regression/Jet183.jet | 22 ++ .../quick/regression/Jet53.jet | 4 + .../quick/regression/Jet67.jet | 4 + .../quick/regression/Jet68.jet | 11 + .../quick/regression/Jet69.jet | 10 + .../quick/regression/Jet72.jet | 17 ++ .../quick/regression/Jet81.jet | 22 ++ .../quick/regression/OverrideResolution.jet | 16 + .../ScopeForSecondaryConstructors.jet | 17 ++ .../regression/SpecififcityByReceiver.jet | 9 + .../ThisConstructorInGenericClass.jet | 3 + .../regression/WrongTraceInCallResolver.jet | 9 + .../quick/regression/kt251.jet | 33 +++ .../quick/regression/kt303.jet | 11 + .../org/jetbrains/jet/JetLiteFixture.java | 4 +- .../org/jetbrains/jet/JetTestCaseBase.java | 6 +- .../jet/checkers/FullJetPsiCheckerTest.java | 115 +++++++ .../jet/checkers/QuickJetPsiCheckerTest.java | 32 ++ 125 files changed, 4924 insertions(+), 4 deletions(-) create mode 100644 idea/testData/checkerWithErrorTypes/full/Abstract.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/BinaryCallsOnNullableValues.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Bounds.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/BreakContinue.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Builders.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Casts.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/ClassObjects.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Constants.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/CyclicHierarchy.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Enums.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/ForRangeConventions.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/GenericArgumentConsistency.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/IncDec.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/IsExpressions.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/MultipleBounds.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/NamespaceAsExpression.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/NamespaceQualified.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Nullability.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Objects.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Override.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/PrimaryConstructors.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/ProjectionsInSupertypes.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Properties.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/QualifiedThis.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/RecursiveTypeInference.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/ResolveToJava.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/StringTemplates.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/SupertypeListChecks.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/TraitSupertypeList.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Unresolved.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/Variance.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/When.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/AmbiguityOnLazyTypeComputation.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet121.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet124.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet169.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet17.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet183.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet53.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet67.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet68.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet69.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet72.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/Jet81.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/OverrideResolution.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/SpecififcityByReceiver.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/ThisConstructorInGenericClass.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/WrongTraceInCallResolver.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/kt251.jet create mode 100644 idea/testData/checkerWithErrorTypes/full/regression/kt303.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/AnonymousInitializers.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/BinaryCallsOnNullableValues.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Bounds.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/BreakContinue.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Builders.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Casts.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/ClassObjects.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Constants.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/CyclicHierarchy.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Enums.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/ExtensionFunctions.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/ForRangeConventions.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/FunctionReturnTypes.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/GenericArgumentConsistency.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/IncDec.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/IsExpressions.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/MultipleBounds.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/NamespaceAsExpression.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/NamespaceQualified.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Nullability.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Objects.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Override.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/PrimaryConstructors.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/ProjectionsInSupertypes.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Properties.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/QualifiedExpressions.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/QualifiedThis.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/RecursiveTypeInference.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/ResolveToJava.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/StringTemplates.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/SupertypeListChecks.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/TraitSupertypeList.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/UnreachableCode.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Unresolved.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/Variance.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/When.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/AmbiguityOnLazyTypeComputation.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/AssignmentsUnderOperators.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/CoercionToUnit.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/DoubleDefine.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet121.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet124.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet169.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet17.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet183-1.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet183.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet53.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet67.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet68.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet69.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet72.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/Jet81.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/OverrideResolution.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/ScopeForSecondaryConstructors.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/SpecififcityByReceiver.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/ThisConstructorInGenericClass.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/WrongTraceInCallResolver.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/kt251.jet create mode 100644 idea/testData/checkerWithErrorTypes/quick/regression/kt303.jet create mode 100644 idea/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java diff --git a/idea/src/org/jetbrains/jet/checkers/CheckerTestUtil.java b/idea/src/org/jetbrains/jet/checkers/CheckerTestUtil.java index 895019da95c..2654c959201 100644 --- a/idea/src/org/jetbrains/jet/checkers/CheckerTestUtil.java +++ b/idea/src/org/jetbrains/jet/checkers/CheckerTestUtil.java @@ -152,6 +152,8 @@ public class CheckerTestUtil { offsetCompensation += matchedText.length(); } + assert opened.isEmpty() : "Stack is not empty"; + matcher.reset(); return matcher.replaceAll(""); } @@ -186,6 +188,13 @@ public class CheckerTestUtil { } result.append(c); } + while (!opened.isEmpty() && text.length() == opened.peek().end) { + closeDiagnosticString(result); + opened.pop(); + } + + assert opened.isEmpty() : "Stack is not empty"; + } else { result.append(text); diff --git a/idea/testData/checkerWithErrorTypes/full/Abstract.jet b/idea/testData/checkerWithErrorTypes/full/Abstract.jet new file mode 100644 index 00000000000..113ff0a34d6 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Abstract.jet @@ -0,0 +1,241 @@ +namespace abstract + +class MyClass() { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } + abstract var c2: Int set(v: Int) { $c2 = v } + abstract var c3: Int = 0; set(v: Int) { $c3 = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} + +abstract class MyAbstractClass() { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } + abstract var c2: Int set(v: Int) { $c2 = v } + abstract var c3: Int = 0; set(v: Int) { $c3 = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} + +trait MyTrait { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } + abstract var c2: Int set(v: Int) { $c2 = v } + abstract var c3: Int = 0; set(v: Int) { $c3 = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} + +enum class MyEnum() { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } + abstract var c2: Int set(v: Int) { $c2 = v } + abstract var c3: Int = 0; set(v: Int) { $c3 = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} + +abstract enum class MyAbstractEnum() {} + +namespace MyNamespace { + //properties + val a: Int + val a1: Int = 1 + abstract val a2: Int + abstract val a3: Int = 1 + + var b: Int private set + var b1: Int = 0; private set + abstract var b2: Int private set + abstract var b3: Int = 0; private set + + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } + abstract var c2: Int set(v: Int) { $c2 = v } + abstract var c3: Int = 0; set(v: Int) { $c3 = v } + + val e: Int get() = a + val e1: Int = 0; get() = a + abstract val e2: Int get() = a + abstract val e3: Int = 0; get() = a + + //methods + fun f() + fun g() {} + abstract fun h() + abstract fun j() {} + + //property accessors + var i: Int abstract get abstract set + var i1: Int = 0; abstract get abstract set + + var j: Int get() = i; abstract set + var j1: Int = 0; get() = i; abstract set + + var k: Int abstract set + var k1: Int = 0; abstract set + + var l: Int abstract get abstract set + var l1: Int = 0; abstract get abstract set + + var n: Int abstract get abstract set(v: Int) {} +} + +//creating an instance +abstract class B1( + val i: Int, + val s: String +) { +} + +class B2() : B1(1, "r") {} + +abstract class B3(i: Int) { + this(): this(1) +} + +fun foo(a: B3) { + val a = B3() + val b = B1(2, "s") +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet b/idea/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet new file mode 100644 index 00000000000..955798a7a9c --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/AnonymousInitializers.jet @@ -0,0 +1,34 @@ +class NoC { + { + + } + + val a : Int get() = 1 + + { + + } +} + +class WithC() { + val x : Int + { + $x = 1 + $y = 2 + val b = x + + } + + val a : Int get() = 1 + + { + val z = b + val zz = x + val zzz = $a + } + + this(a : Int) : this() { + val b = x + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/BinaryCallsOnNullableValues.jet b/idea/testData/checkerWithErrorTypes/full/BinaryCallsOnNullableValues.jet new file mode 100644 index 00000000000..86d34c881be --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/BinaryCallsOnNullableValues.jet @@ -0,0 +1,41 @@ +class A() { + fun equals(a : Any?) : Boolean = false +} + +class B() { + fun equals(a : Any?) : Boolean? = false +} + +class C() { + fun equals(a : Any?) : Int = 0 +} + +fun f(): Unit { + var x: Int? = 1 + x = 1 + x + 1 + x plus 1 + x < 1 + x += 1 + + x == 1 + x != 1 + + A() == 1 + B() == 1 + C() == 1 + + x === "1" + x !== "1" + + x === 1 + x !== 1 + + x..2 + x in 1..2 + + val y : Boolean? = true + false || y + y && true + y && 1 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Bounds.jet b/idea/testData/checkerWithErrorTypes/full/Bounds.jet new file mode 100644 index 00000000000..37066cb74ab --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Bounds.jet @@ -0,0 +1,40 @@ +namespace boundsWithSubstitutors { + open class A + class B>() + + class C : A + + val a = B() + val a1 = B<Int>() + + class X() + + val b = X, C>> + val b0 = XAny?> + val b1 = X, String>> + +} + + open class A {} + open class B() + + abstract class CInt>, X : fun (B<Char>) : (B<Any>, B)>() : B<Any>() { // 2 errors + val a = B<Char>() // error + + abstract val x : fun (B<Char>) : B<Any> + } + + +fun test() { + foo<Int?>() + foo() + bar() + bar() + bar<Double?>() + bar<Double>() + 1.buzz<Double>() +} + +fun foo() {} +fun bar() {} +fun Int> Int.buzz() : Unit {} diff --git a/idea/testData/checkerWithErrorTypes/full/BreakContinue.jet b/idea/testData/checkerWithErrorTypes/full/BreakContinue.jet new file mode 100644 index 00000000000..2bf691799e0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/BreakContinue.jet @@ -0,0 +1,28 @@ +class C { + + fun f (a : Boolean, b : Boolean) { + @b (while (true) + @a { + break@f + break + break@b + break@a + }) + + continue + + @b (while (true) + @a { + continue@f + continue + continue@b + continue@a + }) + + break + + continue@f + break@f + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Builders.jet b/idea/testData/checkerWithErrorTypes/full/Builders.jet new file mode 100644 index 00000000000..1d26cbbc8b2 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Builders.jet @@ -0,0 +1,121 @@ +import java.util.* + +namespace html { + + abstract class Factory { + abstract fun create() : T + } + + abstract class Element + + class TextElement(val text : String) : Element + + abstract class Tag(val name : String) : Element { + val children = ArrayList() + val attributes = HashMap() + + protected fun initTag(init : fun T.() : Unit) : T + where class object T : Factory{ + val tag = T.create() + tag.init() + children.add(tag) + return tag + } + } + + abstract class TagWithText(name : String) : Tag(name) { + fun String.plus() { + children.add(TextElement(this)) + } + } + + class HTML() : TagWithText("html") { + class object : Factory { + override fun create() = HTML() + } + + fun head(init : fun Head.() : Unit) = initTag(init) + + fun body(init : fun Body.() : Unit) = initTag(init) + } + + class Head() : TagWithText("head") { + class object : Factory { + override fun create() = Head() + } + + fun title(init : fun Title.() : Unit) = initTag(init) + } + + class Title() : TagWithText("title") + + abstract class BodyTag(name : String) : TagWithText(name) { + } + + class Body() : BodyTag("body") { + class object : Factory<Body> { + override fun create() = Body() + } + + fun b(init : fun B.() : Unit) = initTag<B>(init) + fun p(init : fun P.() : Unit) = initTag<P>(init) + fun h1(init : fun H1.() : Unit) = initTag<H1>(init) + fun a(href : String, init : fun A.() : Unit) { + val a = initTag<A>(init) + a.href = href + } + } + + class B() : BodyTag("b") + class P() : BodyTag("p") + class H1() : BodyTag("h1") + class A() : BodyTag("a") { + var href : String + get() = attributes["href"] + set(value) { attributes["href"] = value } + } + + fun Map<String, String>.set(key : String, value : String) = this.put(key, value) + + fun html(init : fun HTML.() : Unit) : HTML { + val html = HTML() + html.init() + return html + } + +} + +namespace foo { + +import html.* + +fun result(args : Array<String>) = + html { + head { + title {+"XML encoding with Groovy"} + } + body { + h1 {+"XML encoding with Groovy"} + p {+"this format can be used as an alternative markup to XML"} + + // an element with attributes and text content + a(href = "http://groovy.codehaus.org") {+"Groovy"} + + // mixed content + p { + +"This is some" + b {+"mixed"} + +"text. For more see the" + a(href = "http://groovy.codehaus.org") {+"Groovy"} + +"project" + } + p {+"some text"} + + // content generated by + p { + for (arg in args) + +arg + } + } + } +} diff --git a/idea/testData/checkerWithErrorTypes/full/Casts.jet b/idea/testData/checkerWithErrorTypes/full/Casts.jet new file mode 100644 index 00000000000..163619fd4d0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Casts.jet @@ -0,0 +1,16 @@ +fun test() : Unit { + var x : Int? = 0 + var y : Int = 0 + + x : Int? + y : Int + x as Int : Int + y <!USELESS_CAST!>as<!> Int : Int + x <!USELESS_CAST!>as<!> Int? : Int? + y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int? : Int? + x as? Int : Int? + y <!USELESS_CAST!>as?<!> Int : Int? + x <!USELESS_CAST!>as?<!> Int? : Int? + y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as?<!> Int? : Int? + () +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/ClassObjects.jet b/idea/testData/checkerWithErrorTypes/full/ClassObjects.jet new file mode 100644 index 00000000000..5be76d57e39 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ClassObjects.jet @@ -0,0 +1,30 @@ +namespace Jet86 + +class A { + class object { + val x = 1 + } + <!MANY_CLASS_OBJECTS!>class object { // error + val x = 1 + }<!> +} + +class B() { + val x = 12 +} + +object b { + <!CLASS_OBJECT_NOT_ALLOWED!>class object { + val x = 1 + }<!> // error +} + +val a = A.x +val c = <!NO_CLASS_OBJECT!>B<!>.x +val d = b.<!UNRESOLVED_REFERENCE!>x<!> + +val s = <!NO_CLASS_OBJECT!>System<!> // error +fun test() { + System.out?.println() + java.lang.System.out?.println() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Constants.jet b/idea/testData/checkerWithErrorTypes/full/Constants.jet new file mode 100644 index 00000000000..cc908e189f0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Constants.jet @@ -0,0 +1,8 @@ +fun test() { + 1 : Byte + 1 : Int + <!TYPE_MISMATCH, TYPE_MISMATCH!>1<!> : Double + 1 <!USELESS_CAST!>as<!> Byte + 1 <!USELESS_CAST!>as<!> Int + <!ERROR_COMPILE_TIME_VALUE!>1<!> <!CAST_NEVER_SUCCEEDS!>as<!> Double +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/CyclicHierarchy.jet b/idea/testData/checkerWithErrorTypes/full/CyclicHierarchy.jet new file mode 100644 index 00000000000..ff99017a12b --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/CyclicHierarchy.jet @@ -0,0 +1,30 @@ +open trait A { + fun foo() {} +} +open trait B : A, <!CYCLIC_INHERITANCE_HIERARCHY!>E<!> {} +open trait C : B {} +open trait D : <!CYCLIC_INHERITANCE_HIERARCHY!>B<!> {} +open trait E : <!CYCLIC_INHERITANCE_HIERARCHY!>F<!> {} +open trait F : <!CYCLIC_INHERITANCE_HIERARCHY!>D<!>, C {} +open trait G : F {} +open trait H : F {} + +val a : A? = null +val b : B? = null +val c : C? = null +val d : D? = null +val e : E? = null +val f : F? = null +val g : G? = null +val h : H? = null + +fun test() { + a?.foo() + b?.foo() + c?.foo() + d?.foo() + e?.<!UNRESOLVED_REFERENCE!>foo<!>() + f?.foo() + g?.foo() + h?.foo() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Enums.jet b/idea/testData/checkerWithErrorTypes/full/Enums.jet new file mode 100644 index 00000000000..0ef400fda22 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Enums.jet @@ -0,0 +1,10 @@ +enum class List<out T>(val size : Int) { + Nil : List<Nothing>(0) { + val a = 1 + } + Cons<out T>(val head : T, val tail : List<T>) : List<T>(tail.size + 1) + +} + +val foo = List.Nil +val foo1 = foo.a \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet b/idea/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet new file mode 100644 index 00000000000..54edfbaa527 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ExtensionFunctions.jet @@ -0,0 +1,71 @@ +fun Int?.optint() : Unit {} +val Int?.optval : Unit = () + +fun <T, E> T.foo(x : E, y : A) : T { + y.plus(1) + y plus 1 + y + 1.0 + + this<!UNNECESSARY_SAFE_CALL!>?.<!>minus<T>(this) + + return this +} + +class A + +fun A.plus(a : Any) { + + 1.foo() + true.<!NONE_APPLICABLE!>foo()<!> + + 1 +} + +fun A.plus(a : Int) { + 1 +} + +fun <T> T.minus(t : T) : Int = 1 + +fun test() { + val y = 1.abs +} +val Int.abs : Int + get() = if (this > 0) this else -this; + +val <T> T.<!MUST_BE_INITIALIZED!>foo<!> : T + +fun Int.foo() = this + +namespace null_safety { + + fun parse(cmd: String): Command? { return null } + class Command() { + // fun equals(other : Any?) : Boolean + val foo : Int = 0 + } + + fun Any.equals(other : Any?) : Boolean = true + fun Any?.equals1(other : Any?) : Boolean = true + fun Any.equals2(other : Any?) : Boolean = true + + fun main(args: Array<String>) { + + System.out?.print(1) + + val command = parse("") + + command<!UNSAFE_CALL!>.<!>foo + + command.equals(null) + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null) + command.equals1(null) + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals1(null) + + val c = Command() + c<!UNNECESSARY_SAFE_CALL!>?.<!>equals2(null) + + if (command == null) 1 + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/ForRangeConventions.jet b/idea/testData/checkerWithErrorTypes/full/ForRangeConventions.jet new file mode 100644 index 00000000000..1f14e587fcd --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ForRangeConventions.jet @@ -0,0 +1,81 @@ +import java.util.*; + +class NotRange1() { + +} + +abstract class NotRange2() { + abstract fun iterator() : Unit +} + +abstract class ImproperIterator1 { + abstract fun hasNext() : Boolean +} + +abstract class NotRange3() { + abstract fun iterator() : ImproperIterator1 +} + +abstract class ImproperIterator2 { + abstract fun next() : Boolean +} + +abstract class NotRange4() { + abstract fun iterator() : ImproperIterator2 +} + +abstract class ImproperIterator3 { + abstract fun hasNext() : Int + abstract fun next() : Int +} + +abstract class NotRange5() { + abstract fun iterator() : ImproperIterator3 +} + +abstract class AmbiguousHasNextIterator { + abstract fun hasNext() : Boolean + val hasNext : Boolean get() = false + abstract fun next() : Int +} + +abstract class NotRange6() { + abstract fun iterator() : AmbiguousHasNextIterator +} + +abstract class ImproperIterator4 { + val hasNext : Int get() = 1 + abstract fun next() : Int +} + +abstract class NotRange7() { + abstract fun iterator() : ImproperIterator3 +} + +abstract class GoodIterator { + abstract fun hasNext() : Boolean + abstract fun next() : Int +} + +abstract class Range0() { + abstract fun iterator() : GoodIterator +} + +abstract class Range1() { + abstract fun iterator() : Iterator<Int> +} + +fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRange4: NotRange4, notRange5: NotRange5, notRange6: NotRange6, notRange7: NotRange7, range0: Range0, range1: Range1) { + for (i in <!ITERATOR_MISSING!>notRange1<!>); + for (i in <!HAS_NEXT_MISSING, NEXT_MISSING!>notRange2<!>); + for (i in <!NEXT_MISSING!>notRange3<!>); + for (i in <!HAS_NEXT_MISSING!>notRange4<!>); + for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange5<!>); + for (i in <!HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY!>notRange6<!>); + for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange7<!>); + for (i in range0); + for (i in range1); + + for (i in (ArrayList<Int>() : List<Int>)); +} + diff --git a/idea/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet b/idea/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet new file mode 100644 index 00000000000..64012287566 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/FunctionReturnTypes.jet @@ -0,0 +1,166 @@ +fun none() {} + +fun unitEmptyInfer() {} +fun unitEmpty() : Unit {} +fun unitEmptyReturn() : Unit {return} +fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>} +fun unitUnitReturn() : Unit {return ()} +fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!>} +fun test2() : Any = @a {return@a 1} +fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> } + +fun bbb() { + return <!TYPE_MISMATCH!>1<!> +} + +fun foo(expr: StringBuilder): Int { + val c = 'a' + when(c) { + 0.chr => throw Exception("zero") + else => throw Exception("nonzero" + c) + } +} + + +fun unitShort() : Unit = () +fun unitShortConv() : Unit = <!TYPE_MISMATCH!>1<!> +fun unitShortNull() : Unit = <!TYPE_MISMATCH!>null<!> + +fun intEmpty() : Int <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> +fun intShortInfer() = 1 +fun intShort() : Int = 1 +//fun intBlockInfer() {1} +fun intBlock() : Int {return 1} +fun intBlock() : Int {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1<!>} + +fun intString(): Int = <!TYPE_MISMATCH!>"s"<!> +fun intFunctionLiteral(): Int = <!TYPE_MISMATCH!>{ 10 }<!> + +fun blockReturnUnitMismatch() : Int {<!RETURN_TYPE_MISMATCH!>return<!>} +fun blockReturnValueTypeMismatch() : Int {return <!ERROR_COMPILE_TIME_VALUE!>3.4<!>} +fun blockReturnValueTypeMatch() : Int {return 1} +fun blockReturnValueTypeMismatchUnit() : Int {return <!TYPE_MISMATCH!>()<!>} + +fun blockAndAndMismatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true && false<!> +} +fun blockAndAndMismatch() : Int { + return <!TYPE_MISMATCH!>true && false<!> +} +fun blockAndAndMismatch() : Int { + <!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) && (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!> +} + +fun blockAndAndMismatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true || false<!> +} +fun blockAndAndMismatch() : Int { + return <!TYPE_MISMATCH!>true || false<!> +} +fun blockAndAndMismatch() : Int { + <!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) || (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!> +} +fun blockReturnValueTypeMatch() : Int { + return if (1 > 2) <!ERROR_COMPILE_TIME_VALUE!>1.0<!> else <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) 1<!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) else 1<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + else return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!> + else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + 1.0 + else 2.0 + return 1 +} +fun blockReturnValueTypeMatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2) + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) + 1<!> +} +fun blockReturnValueTypeMatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2) + else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return 1 + else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> +} +fun blockNoReturnIfValDeclaration(): Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val x = 1<!> +} +fun blockNoReturnIfEmptyIf(): Int { + if (1 < 2) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> +} +fun blockNoReturnIfUnitInOneBranch(): Int { + if (1 < 2) { + return 1 + } else { + if (3 < 4) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{ + }<!> else { + return 2 + } + } +} +fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!> +fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2 + +val a = <!RETURN_NOT_ALLOWED!>return 1<!> + +class A() { + this(a : Int) : this() { + if (a == 1) + return + return <!TYPE_MISMATCH!>1<!> + } + +} +fun illegalConstantBody(): Int = <!TYPE_MISMATCH!>"s"<!> +fun illegalConstantBlock(): String { + return <!ERROR_COMPILE_TIME_VALUE!>1<!> +} +fun illegalIfBody(): Int = + if (1 < 2) <!ERROR_COMPILE_TIME_VALUE!>'a'<!> else { <!ERROR_COMPILE_TIME_VALUE!>1.0<!> } +fun illegalIfBlock(): Boolean { + if (1 < 2) + return false + else { return <!ERROR_COMPILE_TIME_VALUE!>1<!> } +} +fun illegalReturnIf(): Char { + return if (1 < 2) 'a' else { <!ERROR_COMPILE_TIME_VALUE!>1<!> } +} + +fun returnNothing(): Nothing { + throw 1 +} +fun f(): Int { + if (1 < 2) { return 1 } else returnNothing() +} + +fun f(): Int = if (1 < 2) 1 else returnNothing() diff --git a/idea/testData/checkerWithErrorTypes/full/GenericArgumentConsistency.jet b/idea/testData/checkerWithErrorTypes/full/GenericArgumentConsistency.jet new file mode 100644 index 00000000000..fafd2cf98c8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/GenericArgumentConsistency.jet @@ -0,0 +1,42 @@ +trait A<in T> {} +trait B<T> : A<Int> {} +trait C<T> : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>B<T>, A<T><!> {} +trait C1<T> : B<T>, A<Any> {} +trait D : <!INCONSISTENT_TYPE_PARAMETER_VALUES, INCONSISTENT_TYPE_PARAMETER_VALUES!>C<Boolean>, B<Double><!>{} + +trait A1<out T> {} +trait B1 : A1<Int> {} +trait B2 : A1<Any>, B1 {} + +trait BA1<T> {} +trait BB1 : BA1<Int> {} +trait BB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>BA1<Any>, BB1<!> {} + + +namespace x { + trait AA1<out T> {} + trait AB1 : AA1<Int> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : AA1<Number>, AB1, AB3 {} +} + +namespace x2 { + trait AA1<out T> {} + trait AB1 : AA1<Any> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {} +} + +namespace x3 { + trait AA1<in T> {} + trait AB1 : AA1<Any> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : AA1<Number>, AB1, AB3 {} +} + +namespace sx2 { + trait AA1<in T> {} + trait AB1 : AA1<Int> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {} +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/IncDec.jet b/idea/testData/checkerWithErrorTypes/full/IncDec.jet new file mode 100644 index 00000000000..5b7143f3eef --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/IncDec.jet @@ -0,0 +1,46 @@ +class IncDec() { + fun inc() : IncDec = this + fun dec() : IncDec = this +} + +fun testIncDec() { + var x = IncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x +} + +class WrongIncDec() { + fun inc() : Int = 1 + fun dec() : Int = 1 +} + +fun testWrongIncDec() { + var x = WrongIncDec() + x<!RESULT_TYPE_MISMATCH!>++<!> + <!RESULT_TYPE_MISMATCH!>++<!>x + x<!RESULT_TYPE_MISMATCH!>--<!> + <!RESULT_TYPE_MISMATCH!>--<!>x +} + +class UnitIncDec() { + fun inc() : Unit {} + fun dec() : Unit {} +} + +fun testUnitIncDec() { + var x = UnitIncDec() + x++ + ++x + x-- + --x + x = <!TYPE_MISMATCH!>x++<!> + x = <!TYPE_MISMATCH!>x--<!> + x = <!TYPE_MISMATCH!>++x<!> + x = <!TYPE_MISMATCH!>--x<!> +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/IsExpressions.jet b/idea/testData/checkerWithErrorTypes/full/IsExpressions.jet new file mode 100644 index 00000000000..960f3711e37 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/IsExpressions.jet @@ -0,0 +1,7 @@ +fun test() { + if (1 is Int) { + if (1 is <!INCOMPATIBLE_TYPES!>Boolean<!>) { + + } + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/MultipleBounds.jet b/idea/testData/checkerWithErrorTypes/full/MultipleBounds.jet new file mode 100644 index 00000000000..773ebaea33f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/MultipleBounds.jet @@ -0,0 +1,72 @@ +namespace Jet87 + +open class A() { + fun foo() : Int = 1 +} + +trait B { + fun bar() : Double = 1.0; +} + +class C() : A(), B + +class D() { + class object : A(), B {} +} + +class Test1<T : A>() + where + T : B, + <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, // error + class object T : A, + class object T : B, + class object <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T + { + + fun test(t : T) { + T.foo() + T.bar() + t.foo() + t.bar() + } +} + +fun test() { + Test1<<!UPPER_BOUND_VIOLATED!>B<!>>() + Test1<<!UPPER_BOUND_VIOLATED!>A<!>>() + Test1<C>() +} + +class Foo() {} + +class Bar<T : <!FINAL_UPPER_BOUND!>Foo<!>> + +class Buzz<T> where T : <!FINAL_UPPER_BOUND!>Bar<<!UPPER_BOUND_VIOLATED!>Int<!>><!>, T : <!UNRESOLVED_REFERENCE!>nioho<!> + +class X<T : <!FINAL_UPPER_BOUND!>Foo<!>> +class Y<<!CONFLICTING_UPPER_BOUNDS!>T<!> : <!FINAL_UPPER_BOUND!>Foo<!>> where T : <!FINAL_UPPER_BOUND!>Bar<Foo><!> + +fun <T : A> test2(t : T) + where + T : B, + <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, + class object <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, + class object T : B, + class object T : A +{ + T.foo() + T.bar() + t.foo() + t.bar() +} + +val t1 = test2<<!UPPER_BOUND_VIOLATED!>A<!>>(A()) +val t2 = test2<<!UPPER_BOUND_VIOLATED!>B<!>>(C()) +val t3 = test2<C>(C()) + +class Test<<!CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS!>T<!>> + where + class object T : <!FINAL_CLASS_OBJECT_UPPER_BOUND!>Foo<!>, + class object T : A {} + +val <T, B : T> x : Int = 0 diff --git a/idea/testData/checkerWithErrorTypes/full/NamespaceAsExpression.jet b/idea/testData/checkerWithErrorTypes/full/NamespaceAsExpression.jet new file mode 100644 index 00000000000..a7e2a3a78a7 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/NamespaceAsExpression.jet @@ -0,0 +1,8 @@ +namespace root + +namespace a { + +} + +val x = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND, UNRESOLVED_REFERENCE!>a<!> +val y2 = <!NAMESPACE_IS_NOT_AN_EXPRESSION!>namespace<!> diff --git a/idea/testData/checkerWithErrorTypes/full/NamespaceQualified.jet b/idea/testData/checkerWithErrorTypes/full/NamespaceQualified.jet new file mode 100644 index 00000000000..a298efcacfe --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/NamespaceQualified.jet @@ -0,0 +1,63 @@ +namespace foobar + +namespace a { + import java.* + + val a : util.List<Int>? = null + val a1 : <!UNRESOLVED_REFERENCE!>List<!><Int>? = null + +} + +abstract class Foo<T>() { + abstract val x : T<Int> +} + +namespace a { + import java.util.* + + val b : List<Int>? = a + val b1 : <!UNRESOLVED_REFERENCE!>util<!>.List<Int>? = a +} + +val x1 = a.a + +val y1 = a.b + + +///////////////////////////////////////////////////////////////////////// + +fun done<O>(result : O) : Iteratee<Any?, O> = StrangeIterateeImpl<Any?, O>(result) + +abstract class Iteratee<in I, out O> { + abstract fun process(item : I) : Iteratee<I, O> + abstract val isDone : Boolean + abstract val result : O + abstract fun done() : O +} + +class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> { + override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj) + override val isDone = true + override val result = obj + override fun done() = obj +} + +abstract class Sum() : Iteratee<Int, Int> { + override fun process(item : Int) : Iteratee<Int, Int> { + return foobar.done<Int>(item); + } + abstract override val isDone : Boolean + abstract override val result : Int + abstract override fun done() : Int +} + +abstract class Collection<E> : Iterable<E> { + fun iterate<O>(iteratee : Iteratee<E, O>) : O { + for (x in this) { + val it = iteratee.process(x) + if (it.isDone) return it.result + iteratee = it + } + return iteratee.done() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Nullability.jet b/idea/testData/checkerWithErrorTypes/full/Nullability.jet new file mode 100644 index 00000000000..8479b364cd8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Nullability.jet @@ -0,0 +1,280 @@ +fun test() { + val a : Int? = 0 + if (a != null) { + a.plus(1) + } + else { + a?.plus(1) + } + + val out : java.io.PrintStream? = null//= System.out + val ins = System.`in` + + out?.println() + ins?.read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins?.read(); + out.println(); + } + + if (out == null || out.println(0) == ()) { + out?.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == ()) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out != null && out.println() == ()) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == ()) { + out?.println(2); + } + else { + out?.println(3) + } + + out?.println() + ins?.read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins?.read(); + out.println(); + } + + if (out == null || out.println(0) == ()) { + out?.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == ()) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out != null && out.println() == ()) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == ()) { + out?.println(2); + } + else { + out?.println(3) + } + + if (1 > 2) { + if (out == null) return; + out.println(); + } + out?.println(); + + while (out != null) { + out.println(); + } + out?.println(); + + while (out == null) { + out?.println(); + } + out.println() + +} + + +fun f(out : String?) { + out?.get(0) + if (out != null) else return; + out.get(0) +} + +fun f1(out : String?) { + out?.get(0) + if (out != null) else { + 1 + 2 + return; + } + out.get(0) +} + +fun f2(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + out.get(0) +} + +fun f3(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + else { + 1 + 2 + } + out.get(0) +} + +fun f4(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + s?.get(0) + } + s.get(0) +} + +fun f5(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + if (1 > 2) break + s?.get(0) + } + s?.get(0); +} + +fun f6(s : String?) { + s?.get(0) + do { + s?.get(0) + if (1 < 2) break; + } while (s == null) + s?.get(0) + do { + s?.get(0) + } while (s == null) + s.get(0) +} + +fun f7(s : String?, t : String?) { + s?.get(0) + if (!(s == null)) { + s.get(0) + } + s?.get(0) + if (!(s != null)) { + s?.get(0) + } + else { + s.get(0) + } + s?.get(0) + if (!!(s != null)) { + s.get(0) + } + else { + s?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null || t == null)) { + s.get(0) + t.get(0) + } + else { + s?.get(0) + t?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null && s == null)) { + s.get(0) + t?.get(0) + } + else { + s?.get(0) + t?.get(0) + } +} + +fun f8(b : String?, a : String) { + b?.get(0) + if (b == a) { + b.get(0); + } + b?.get(0) + if (a == b) { + b.get(0) + } + if (a != b) { + b?.get(0) + } + else { + b.get(0) + } +} + +fun f9(a : Int?) : Int { + if (a != null) + return a + return 1 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Objects.jet b/idea/testData/checkerWithErrorTypes/full/Objects.jet new file mode 100644 index 00000000000..79ed4e42644 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Objects.jet @@ -0,0 +1,83 @@ +namespace toplevelObjectDeclarations { + open class Foo(y : Int) { + open fun foo() : Int = 1 + } + + class T : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> {} + + object A : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> { + val x : Int = 2 + + fun test() : Int { + return x + foo() + } + } + + object B : <!UNRESOLVED_REFERENCE!>A<!> {} + + val x = A.foo() + + val y = object : Foo(x) { + { + x + 12 + } + + override fun foo() : Int = 1 + } + + val z = y.foo() +} + +namespace nestedObejcts { + object A { + val b = B + val d = A.B.A + + object B { + val a = A + val e = B.A + + object A { + val a = A + val b = B + val x = nestedObejcts.A.B.A + val y = this<!AMBIGUOUS_LABEL!>@A<!> + } + } + + } + object B { + val b = B + val c = A.B + } + + val a = A + val b = B + val c = A.B + val d = A.B.A + val e = B.<!UNRESOLVED_REFERENCE!>A<!>.B +} + +namespace localObjects { + object A { + val x : Int = 0 + } + + open class Foo { + fun foo() : Int = 1 + } + + fun test() { + A.x + val b = object : Foo { + } + b.foo() + + object B { + fun foo() {} + } + B.foo() + } + + val bb = <!UNRESOLVED_REFERENCE!>B<!>.foo() +} diff --git a/idea/testData/checkerWithErrorTypes/full/Override.jet b/idea/testData/checkerWithErrorTypes/full/Override.jet new file mode 100644 index 00000000000..fecb1c72304 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Override.jet @@ -0,0 +1,76 @@ +namespace override + +namespace normal { + trait MyTrait { + fun foo() + } + + abstract class MyAbstractClass { + abstract fun bar() + } + + open class MyClass : MyTrait, MyAbstractClass { + override fun foo() {} + override fun bar() {} + } + + class MyChildClass : MyClass {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass2<!> : MyTrait, MyAbstractClass { + override fun foo() {} + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass3<!> : MyTrait, MyAbstractClass { + override fun bar() {} + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass4<!> : MyTrait, MyAbstractClass { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>() {} + <!NOTHING_TO_OVERRIDE!>override<!> fun other() {} + } + + class MyChildClass1 : MyClass { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>() {} + override fun bar() {} + } +} + +namespace generics { + trait MyTrait<T> { + fun foo(t: T) : T + } + + abstract class MyAbstractClass<T> { + abstract fun bar(t: T) : T + } + + open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T> { + override fun foo(t: T) = t + override fun bar(t: T) = t + } + + class MyChildClass : MyGenericClass<Int> {} + class MyChildClass1<T> : MyGenericClass<T> {} + class MyChildClass2<T> : MyGenericClass<T> { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>(t: T) = t + override fun bar(t: T) = t + } + + open class MyClass : MyTrait<Int>, MyAbstractClass<String> { + override fun foo(i: Int) = i + override fun bar(s: String) = s + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T> {} + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R> : MyTrait<T>, MyAbstractClass<R> { + <!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r + } + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String> {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass2<!><T> : MyTrait<Int>, MyAbstractClass<Int> { + fun foo(t: T) = t + fun bar(t: T) = t + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/PrimaryConstructors.jet b/idea/testData/checkerWithErrorTypes/full/PrimaryConstructors.jet new file mode 100644 index 00000000000..8756860955f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/PrimaryConstructors.jet @@ -0,0 +1,14 @@ +class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>X<!> { + val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int +} + +open class Y() { + val x : Int = 2 +} + +class Y1 { + val x : Int get() = 1 +} + +class Z : Y<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!> { +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/ProjectionsInSupertypes.jet b/idea/testData/checkerWithErrorTypes/full/ProjectionsInSupertypes.jet new file mode 100644 index 00000000000..c02bb72b6a2 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ProjectionsInSupertypes.jet @@ -0,0 +1,6 @@ +trait A<T> {} +trait B<T> {} +trait C<T> {} +trait D<T> {} + +trait Test : A<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>in<!> Int>, B<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>out<!> Int>, C<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>*<!>><!NULLABLE_SUPERTYPE!>?<!><!NULLABLE_SUPERTYPE!>?<!><!NULLABLE_SUPERTYPE!>?<!>, D<Int> {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Properties.jet b/idea/testData/checkerWithErrorTypes/full/Properties.jet new file mode 100644 index 00000000000..999ebc5173e --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Properties.jet @@ -0,0 +1,28 @@ + var x : Int = 1 + x + get() : Int = 1 + set(<!REF_SETTER_PARAMETER!>ref<!> value : <!WRONG_SETTER_PARAMETER_TYPE!>Long<!>) { + $x = value.int + $x = <!TYPE_MISMATCH!>1.lng<!> + } + + val xx : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1 + x<!> + get() : Int = 1 + <!VAL_WITH_SETTER!>set(value : Long) {}<!> + + val p : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!> + get() = 1 + +class Test() { + var a : Int = 111 + var b : Int get() = <!UNRESOLVED_REFERENCE!>$a<!>; set(x) {a = x; <!UNRESOLVED_REFERENCE!>$a<!> = x} + + this(i : Int) : this() { + <!NO_BACKING_FIELD!>$b<!> = $a + $a = <!NO_BACKING_FIELD!>$b<!> + a = <!NO_BACKING_FIELD!>$b<!> + } + fun f() { + <!UNRESOLVED_REFERENCE!>$b<!> = <!UNRESOLVED_REFERENCE!>$a<!> + a = <!UNRESOLVED_REFERENCE!>$b<!> + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet b/idea/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet new file mode 100644 index 00000000000..67233fd840f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/QualifiedExpressions.jet @@ -0,0 +1,11 @@ +namespace qualified_expressions + +fun test(s: String?) { + val a: Int = <!TYPE_MISMATCH!>s?.length<!> + val b: Int? = s?.length + val c: Int = s?.length ?: -11 + val d: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!> + val e: String = <!TYPE_MISMATCH!>s?.length<!> ?: "empty" + val f: Int = s?.length ?: b ?: 1 + val g: Int? = e? startsWith("s")?.length +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/QualifiedThis.jet b/idea/testData/checkerWithErrorTypes/full/QualifiedThis.jet new file mode 100644 index 00000000000..f23c01cfd20 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/QualifiedThis.jet @@ -0,0 +1,41 @@ +class Dup { + fun Dup() : Unit { + this<!AMBIGUOUS_LABEL!>@Dup<!> + } +} + +class A() { + fun foo() : Unit { + this@A + this<!UNRESOLVED_REFERENCE!>@a<!> + this + } + + val x = this@A.foo() + val y = this.foo() + val z = foo() +} + +fun foo1() : Unit { + <!NO_THIS!>this<!> + this<!UNRESOLVED_REFERENCE!>@a<!> +} + +namespace closures { + class A(val a:Int) { + + class B() { + val x = this@B : B + val y = this@A : A + val z = this : B + val Int.xx = this : Int + fun Char.xx() : Any { + this : Char + val a = {Double.() => this : Double + this@xx : Char} + val b = @a{Double.() => this@a : Double + this@xx : Char} + val c = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char} + return (@a{Double.() => this@a : Double + this@xx : Char}) + } + } + } +} diff --git a/idea/testData/checkerWithErrorTypes/full/RecursiveTypeInference.jet b/idea/testData/checkerWithErrorTypes/full/RecursiveTypeInference.jet new file mode 100644 index 00000000000..11eb880a193 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/RecursiveTypeInference.jet @@ -0,0 +1,42 @@ +namespace a { + val foo = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun bar() = foo +} + +namespace b { + fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun bar() = foo() +} + +namespace c { + fun bazz() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun foo() = bazz() + + fun bar() = foo() +} + +namespace ok { + + namespace a { + val foo = bar() + + fun bar() : Int = foo + } + + namespace b { + fun foo() : Int = bar() + + fun bar() = foo() + } + + namespace c { + fun bazz() = bar() + + fun foo() : Int = bazz() + + fun bar() = foo() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/ResolveToJava.jet b/idea/testData/checkerWithErrorTypes/full/ResolveToJava.jet new file mode 100644 index 00000000000..e2385007530 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ResolveToJava.jet @@ -0,0 +1,52 @@ +import java.* +import util.* +import <!UNRESOLVED_REFERENCE!>utils<!>.* + +import java.io.PrintStream +import java.lang.Comparable as Com + +val l : List<in Int> = ArrayList<Int>() + +fun test(l : java.util.List<Int>) { + val x : java.<!UNRESOLVED_REFERENCE!>List<!> + val y : java.util.List<Int> + val b : java.lang.Object + val a : util.List<Int> + val z : java.<!UNRESOLVED_REFERENCE!>utils<!>.List<Int> + + val f : java.io.File? = null + + Collections.<!UNRESOLVED_REFERENCE!>emptyList<!> + Collections.emptyList<Int> + Collections.emptyList<Int>() + Collections.emptyList() + + Collections.singleton<Int>(1) : Set<Int>? + Collections.singleton<Int>(<!ERROR_COMPILE_TIME_VALUE!>1.0<!>) + + <!UNRESOLVED_REFERENCE!>List<!><Int> + + + val o = "sdf" <!CAST_NEVER_SUCCEEDS!>as<!> Object + + try { + // ... + } + catch(e: Exception) { + System.out?.println(e.getMessage()) + } + + PrintStream("sdf") + + val c : Com<Int>? = null + + c : java.lang.Comparable<Int>? + +// Collections.sort<Integer>(ArrayList<Integer>()) + xxx.<!UNRESOLVED_REFERENCE!>Class<!>() +} + + +namespace xxx { + import java.lang.Class; +} diff --git a/idea/testData/checkerWithErrorTypes/full/StringTemplates.jet b/idea/testData/checkerWithErrorTypes/full/StringTemplates.jet new file mode 100644 index 00000000000..108ffe1d7dd --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/StringTemplates.jet @@ -0,0 +1,21 @@ +fun demo() { + val abc = 1 + val a = "" + val asd = 1 + val bar = 5 + fun map(f : fun () : Any?) : Int = 1 + fun buzz(f : fun () : Any?) : Int = 1 + val sdf = 1 + val foo = 3; + "$abc" + "$" + "$.$.asdf$\t" + "asd\$" + "asd$a<!ILLEGAL_ESCAPE_SEQUENCE!>\x<!>" + "asd$a$asd$ $<!UNRESOLVED_REFERENCE!>xxx<!>" + "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" + "foo${bar + map {foo}}sdfsdf" + "foo${bar + map { "foo" }}sdfsdf" + "foo${bar + map { + "foo$sdf${ buzz{}}" }}sdfsdf" +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/SupertypeListChecks.jet b/idea/testData/checkerWithErrorTypes/full/SupertypeListChecks.jet new file mode 100644 index 00000000000..b63a4d3af5d --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/SupertypeListChecks.jet @@ -0,0 +1,51 @@ +// KT-286 Check supertype lists + +/* +In a supertype list: + Same type should not be mentioned twice + Same type should not be indirectly mentioned with incoherent type arguments + Every trait's required dependencies should be satisfied + No final types should appear + Only one class is allowed +*/ + +class C1() + +open class OC1() + +open class C2 {} + +open class C3 {} + +trait T1 {} + +trait T2<T> {} + +trait Test<!CONSTRUCTOR_IN_TRAIT!>()<!> { + <!CONSTRUCTOR_IN_TRAIT, SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>(x : Int) {} +} + +trait Test1 : C2<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()<!> {} + +trait Test2 : C2 {} + +trait Test3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {} + +trait Test4 : T1 {} + +trait Test5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {} + +trait Test6 : <!FINAL_SUPERTYPE!>C1<!> {} + +class CTest1() : OC1() {} + +class CTest2 : C2 {} + +class CTest3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {} + +class CTest4 : T1 {} + +class CTest5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {} + +class CTest6 : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>C1<!> {} + diff --git a/idea/testData/checkerWithErrorTypes/full/TraitSupertypeList.jet b/idea/testData/checkerWithErrorTypes/full/TraitSupertypeList.jet new file mode 100644 index 00000000000..7f109773457 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/TraitSupertypeList.jet @@ -0,0 +1,11 @@ +open class bar() + +trait Foo<!CONSTRUCTOR_IN_TRAIT!>()<!> : bar<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> { + <!CONSTRUCTOR_IN_TRAIT, SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>(x : Int) {} +} + +trait Foo2 : bar, Foo { +} + +open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {} +open class Foo12 : bar<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>, <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet b/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet new file mode 100644 index 00000000000..2a72a04117d --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/UnreachableCode.jet @@ -0,0 +1,161 @@ +fun t1() : Int{ + return 0 + <!UNREACHABLE_CODE!>1<!> +} + +fun t1a() : Int { + <!RETURN_TYPE_MISMATCH!>return<!> + <!UNREACHABLE_CODE!>return 1<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t1b() : Int { + return 1 + <!UNREACHABLE_CODE!>return 1<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t1c() : Int { + return 1 + <!RETURN_TYPE_MISMATCH, UNREACHABLE_CODE!>return<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t2() : Int { + if (1 > 2) + return 1 + else return 1 + <!UNREACHABLE_CODE!>1<!> +} + +fun t2a() : Int { + if (1 > 2) { + return 1 + <!UNREACHABLE_CODE!>1<!> + } else { return 1 + <!UNREACHABLE_CODE!>2<!> + } + <!UNREACHABLE_CODE!>1<!> +} + +fun t3() : Any { + if (1 > 2) + return 2 + else return "" + <!UNREACHABLE_CODE!>1<!> +} + +fun t4(a : Boolean) : Int { + do { + return 1 + } + while (<!UNREACHABLE_CODE!>a<!>) + <!UNREACHABLE_CODE!>1<!> +} + +fun t4break(a : Boolean) : Int { + do { + break + } + while (<!UNREACHABLE_CODE!>a<!>) + return 1 +} + +fun t5() : Int { + do { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + while (<!UNREACHABLE_CODE!>1 > 2<!>) + <!UNREACHABLE_CODE!>return 1<!> +} + +fun t6() : Int { + while (1 > 2) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t6break() : Int { + while (1 > 2) { + break + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7(b : Int) : Int { + for (i in 1..b) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7break(b : Int) : Int { + for (i in 1..b) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7() : Int { + try { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + catch (e : Any) { + 2 + } + return 1 // this is OK, like in Java +} + +fun t8() : Int { + try { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + catch (e : Any) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + <!UNREACHABLE_CODE!>return 1<!> +} + +fun blockAndAndMismatch() : Boolean { + <!UNREACHABLE_CODE!>(return true) || (return false)<!> + <!UNREACHABLE_CODE!>return true<!> +} + +fun tf() : Int { + try {<!UNREACHABLE_CODE!>return 1<!>} finally{return 1} + <!UNREACHABLE_CODE!>return 1<!> +} + +fun failtest(a : Int) : Int { + <!UNREACHABLE_BECAUSE_OF_NOTHING!>if (fail() || true) { + + }<!> + <!UNREACHABLE_BECAUSE_OF_NOTHING!>return 1<!> +} + +fun foo(a : Nothing) : Unit { + 1 + a + <!UNREACHABLE_BECAUSE_OF_NOTHING!>2<!> +} + +fun fail() : Nothing { + throw java.lang.RuntimeException() +} + +fun nullIsNotNothing() : Unit { + val x : Int? = 1 + if (x != null) { + return + } + fail() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/Unresolved.jet b/idea/testData/checkerWithErrorTypes/full/Unresolved.jet new file mode 100644 index 00000000000..48ea2a58e4d --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Unresolved.jet @@ -0,0 +1,30 @@ +namespace unresolved + +fun testGenericArgumentsCount() { + val p1: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2) + val p2: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2) +} + +fun testUnresolved() { + if (<!UNRESOLVED_REFERENCE!>a<!> is String) { + val s = <!UNRESOLVED_REFERENCE!>a<!> + } + <!UNRESOLVED_REFERENCE!>foo<!>(<!UNRESOLVED_REFERENCE!>a<!>) + val s = "s" + <!UNRESOLVED_REFERENCE!>foo<!>(s) + foo1(<!UNRESOLVED_REFERENCE!>i<!>) + s.<!UNRESOLVED_REFERENCE!>foo<!>() + + when(<!UNRESOLVED_REFERENCE!>a<!>) { + is Int => <!UNRESOLVED_REFERENCE!>a<!> + is String => <!UNRESOLVED_REFERENCE!>a<!> + } + + //TODO + for (j in <!UNRESOLVED_REFERENCE!>collection<!>) { + val i: Int = j + j += 1 + } +} + +fun foo1(i: Int) {} diff --git a/idea/testData/checkerWithErrorTypes/full/Variance.jet b/idea/testData/checkerWithErrorTypes/full/Variance.jet new file mode 100644 index 00000000000..9b6531ffd02 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/Variance.jet @@ -0,0 +1,40 @@ +namespace variance + +abstract class Consumer<in T> {} + +abstract class Producer<out T> {} + +abstract class Usual<T> {} + +fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) { + val c1: Consumer<Any> = <!TYPE_MISMATCH!>c<!> + val c2: Consumer<Int> = c1 + + val p1: Producer<Any> = p + val p2: Producer<Int> = <!TYPE_MISMATCH!>p1<!> + + val u1: Usual<Any> = <!TYPE_MISMATCH!>u<!> + val u2: Usual<Int> = <!TYPE_MISMATCH!>u1<!> +} + +//Arrays copy example +class Array<T>(val length : Int) { + fun get(index : Int) : T { return null } + fun set(index : Int, value : T) { /* ... */ } +} + +fun copy1(from : Array<Any>, to : Array<Any>) {} + +fun copy2(from : Array<out Any>, to : Array<in Any>) {} + +fun <T> copy3(from : Array<out T>, to : Array<in T>) {} + +fun copy4(from : Array<out Number>, to : Array<in Int>) {} + +fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) { + copy1(<!TYPE_MISMATCH!>ints<!>, any) + copy2(ints, any) //ok + copy2(ints, <!TYPE_MISMATCH!>numbers<!>) + copy3<Int>(ints, numbers) + copy4(ints, numbers) //ok +} diff --git a/idea/testData/checkerWithErrorTypes/full/When.jet b/idea/testData/checkerWithErrorTypes/full/When.jet new file mode 100644 index 00000000000..f8612546d1c --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/When.jet @@ -0,0 +1,61 @@ +fun foo() : Int { + val s = "" + val x = 1 + when (x) { + is * => 1 + is <!INCOMPATIBLE_TYPES!>String<!> => 1 + !is Int => 1 + is Any? => 1 + <!INCOMPATIBLE_TYPES!>s<!> => 1 + 1 => 1 + 1 + <!UNRESOLVED_REFERENCE!>a<!> => 1 + in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 + !in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 + .<!UNRESOLVED_REFERENCE!>a<!> => 1 + .equals(1).<!UNRESOLVED_REFERENCE!>a<!> => 1 + <!UNNECESSARY_SAFE_CALL!>?.<!>equals(1) => 1 + else => 1 + } + return when (<!USELESS_ELVIS!>x<!>?:null) { + <!UNSAFE_CALL!>.<!>equals(1) => 1 + ?.equals(1).equals(2) => 1 + } +} + +val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() + +fun test() { + val x = 1; + val s = ""; + + when (x) { + <!INCOMPATIBLE_TYPES!>s<!> => 1 + is <!INCOMPATIBLE_TYPES!>""<!> => 1 + x => 1 + is 1 => 1 + is <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, 1)<!> => 1 + } + + val z = (1, 1) + + when (z) { + is (*, *) => 1 + is (*, 1) => 1 + is (1, 1) => 1 + is (1, <!INCOMPATIBLE_TYPES!>"1"<!>) => 1 + is <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, "1", *)<!> => 1 + is boo @ (1, <!INCOMPATIBLE_TYPES!>"a"<!>, *) => 1 + is boo @ <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, *)<!> => 1 + } + + when (z) { + <!ELSE_MISPLACED_IN_WHEN!>else => 1<!> + (1, 1) => 2 + } + + when (z) { + else => 1 + } +} + +val (Int, Int).boo : (Int, Int, Int) = (1, 1, 1) diff --git a/idea/testData/checkerWithErrorTypes/full/regression/AmbiguityOnLazyTypeComputation.jet b/idea/testData/checkerWithErrorTypes/full/regression/AmbiguityOnLazyTypeComputation.jet new file mode 100644 index 00000000000..779ee4c4d97 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/AmbiguityOnLazyTypeComputation.jet @@ -0,0 +1,12 @@ +// One of the two passes is making a scope and turning vals into functions +// See KT-76 + +namespace x + +val b : Foo = Foo() +val a1 = b.compareTo(2) + +class Foo() { + fun compareTo(other : Byte) : Int = 0 + fun compareTo(other : Char) : Int = 0 +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet b/idea/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet new file mode 100644 index 00000000000..5a7c24b7fd0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/AssignmentsUnderOperators.jet @@ -0,0 +1,6 @@ +fun test() { + val a : Any? = null + if (a is Any) else a = null; + while (a is Any) a = null + while (true) a = null +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet b/idea/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet new file mode 100644 index 00000000000..6733ab3a31e --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/CoercionToUnit.jet @@ -0,0 +1,9 @@ +fun foo(u : Unit) : Int = 1 + +fun test() : Int { + foo(<!TYPE_MISMATCH!>1<!>) + val a : fun() : Unit = { + foo(<!TYPE_MISMATCH!>1<!>) + } + return 1 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet b/idea/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet new file mode 100644 index 00000000000..fbca6a41c99 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/DoubleDefine.jet @@ -0,0 +1,66 @@ +import java.* +import util.* + +import java.io.* + +fun takeFirst(expr: StringBuilder): Char { + val c = expr.charAt(0) + expr.deleteCharAt(0) + return c +} + +fun evaluateArg(expr: AbstractStringBuilder, numbers: ArrayList<Int>): Int { + if (expr.length() == 0) throw Exception("Syntax error: Character expected"); + val c = takeFirst(<!TYPE_MISMATCH!>expr<!>) + if (c >= '0' && c <= '9') { + val n = c - '0' + if (!numbers.contains(n)) throw Exception("You used incorrect number: " + n) + numbers.remove(n) + return n + } + throw Exception("Syntax error: Unrecognized character " + c) +} + +fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int { + val lhs = evaluateArg(expr, numbers) + if (expr.length() > 0) { + + } + return lhs +} + +fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int { + val lhs = evaluateAdd(expr, numbers) + if (expr.length() > 0) { + val c = expr.charAt(0) + expr.deleteCharAt(0) + } + return lhs +} + +fun main(args: Array<String>) { + System.out?.println("24 game") + val numbers = ArrayList<Int>(4) + val rnd = Random(); + val prompt = StringBuilder() + for(val i in 0..3) { + val n = rnd.nextInt(9) + 1 + numbers.add(n) + if (i > 0) prompt.append(" "); + prompt.append(n) + } + System.out?.println("Your numbers: " + prompt) + System.out?.println("Enter your expression:") + val reader = BufferedReader(InputStreamReader(System.`in`)) + val expr = StringBuilder(reader.readLine()) + try { + val result = evaluate(expr, numbers) + if (result != 24) + System.out?.println("Sorry, that's " + result) + else + System.out?.println("You won!"); + } + catch(e: Throwable) { + System.out?.println(e.getMessage()) + } +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet121.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet121.jet new file mode 100644 index 00000000000..fc29dfe5293 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet121.jet @@ -0,0 +1,14 @@ +namespace jet121 { + fun box() : String { + val answer = apply("OK") { String.() : Int => + get(0) + length + } + + return if (answer == 2) "OK" else "FAIL" + } + + fun apply(arg:String, f : fun String.() : Int) : Int { + return arg.f() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet124.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet124.jet new file mode 100644 index 00000000000..317b1438f41 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet124.jet @@ -0,0 +1,8 @@ +fun foo1() : fun (Int) : Int = { (x: Int) => x } + +fun foo() { + val h : fun (Int) : Int = foo1(); + h(1) + val m : fun (Int) : Int = {(a : Int) => 1}//foo1() + m(1) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet169.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet169.jet new file mode 100644 index 00000000000..000536ce340 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet169.jet @@ -0,0 +1,8 @@ +fun set(key : String, value : String) { + val a : String? = "" + when (a) { + "" => a<!UNSAFE_CALL!>.<!>get(0) + is String, is Any => a.compareTo("") + else => a.toString() + } +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet17.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet17.jet new file mode 100644 index 00000000000..32cf98cd2fc --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet17.jet @@ -0,0 +1,6 @@ +// JET-17 Do not infer property types by the initializer before the containing scope is ready + +class WithC() { + val a = 1 + val b = $a // error here, but must not be +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet new file mode 100644 index 00000000000..37c72d83ef6 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet183-1.jet @@ -0,0 +1,21 @@ +abstract enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + } + + TALKING { + override fun signal() = ProtocolState.WAITING + } + + abstract fun signal() : ProtocolState +} + + +fun box(): String { + val x: ProtocolState = ProtocolState.WAITING + x = x.signal() + if (x != ProtocolState.TALKING) return "fail 1" + x = x.signal() + if (x != ProtocolState.WAITING) return "fail 2" + return "OK" +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet183.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet183.jet new file mode 100644 index 00000000000..59df6e106d6 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet183.jet @@ -0,0 +1,22 @@ +abstract enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + } + + TALKING { + override fun signal() = ProtocolState.WAITING + } + + abstract fun signal() : ProtocolState +} + +enum class Foo<T> { + <!NO_GENERICS_IN_SUPERTYPE_SPECIFIER!>X<!> + +} + + + +fun box() { + val x: ProtocolState = ProtocolState.WAITING +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet53.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet53.jet new file mode 100644 index 00000000000..e880fe25bbd --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet53.jet @@ -0,0 +1,4 @@ +import java.util.Collections +import java.util.List + +val ab = Collections.emptyList<Int>() : List<Int>? \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet67.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet67.jet new file mode 100644 index 00000000000..49a449094ec --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet67.jet @@ -0,0 +1,4 @@ +abstract class XXX { + val a : Int abstract get + +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet68.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet68.jet new file mode 100644 index 00000000000..2d9cc4c7b21 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet68.jet @@ -0,0 +1,11 @@ +class Foo() + +fun test() { + val f : Foo? = null + if (f == null) { + + } + if (f != null) { + + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet69.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet69.jet new file mode 100644 index 00000000000..dd198aa0f61 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet69.jet @@ -0,0 +1,10 @@ +class Command() {} + +fun parse(cmd: String): Command? { return null } + +fun Any.equals(other : Any?) : Boolean = this === other + +fun main(args: Array<String>) { + val command = parse("") + if (command == null) 1 // error on this line, but must be OK +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet72.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet72.jet new file mode 100644 index 00000000000..d3d3272c8e3 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet72.jet @@ -0,0 +1,17 @@ +// JET-72 Type inference doesn't work when iterating over ArrayList + +import java.util.ArrayList + +abstract class Item(val room: Object) { + abstract val name : String +} + +val items: ArrayList<Item> = ArrayList<Item> + +fun test(room : Object) { + for(val item: Item in items) { + if (item.room === room) { + System.out?.println("You see " + item.name) + } + } +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/Jet81.jet b/idea/testData/checkerWithErrorTypes/full/regression/Jet81.jet new file mode 100644 index 00000000000..c3df9ba023f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/Jet81.jet @@ -0,0 +1,22 @@ +// JET-81 Assertion fails when processing self-referring anonymous objects + +val y = object { + val a = y; +} + +val z = y.a; + +object A { + val x = A +} + +val a = object { + { + b + 1 + } + val x = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>b<!> + val y = 1 +} + +val b = a.x +val c = a.y diff --git a/idea/testData/checkerWithErrorTypes/full/regression/OverrideResolution.jet b/idea/testData/checkerWithErrorTypes/full/regression/OverrideResolution.jet new file mode 100644 index 00000000000..b58ac616160 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/OverrideResolution.jet @@ -0,0 +1,16 @@ +fun box() { + val a : C + a.foo() +} + +open class A { + open fun foo() {} +} + +open class B : A { + override fun foo() {} +} + +open class C : B { + override fun foo() {} +} diff --git a/idea/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet b/idea/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet new file mode 100644 index 00000000000..2cac1044074 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/ScopeForSecondaryConstructors.jet @@ -0,0 +1,18 @@ + class Foo(var bar : Int, barr : Int, val barrr : Int) { + { + bar = 1 + barr = 1 + barrr = 1 + 1 : Int + this : Foo + } + + this(val bar : Int) : this(1, 1, 1) { + bar = 1 + this.bar + 1 : Int + val a : Int =1 + this : Foo + } + } + diff --git a/idea/testData/checkerWithErrorTypes/full/regression/SpecififcityByReceiver.jet b/idea/testData/checkerWithErrorTypes/full/regression/SpecififcityByReceiver.jet new file mode 100644 index 00000000000..bbca53527c8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/SpecififcityByReceiver.jet @@ -0,0 +1,9 @@ +fun Any.equals(other : Any?) : Boolean = true + +fun main(args: Array<String>) { + + val command : Any = 1 + + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null) + command.equals(null) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/ThisConstructorInGenericClass.jet b/idea/testData/checkerWithErrorTypes/full/regression/ThisConstructorInGenericClass.jet new file mode 100644 index 00000000000..cb4408bd600 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/ThisConstructorInGenericClass.jet @@ -0,0 +1,3 @@ +class Z() { + this(x : Int) : this() {} +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/WrongTraceInCallResolver.jet b/idea/testData/checkerWithErrorTypes/full/regression/WrongTraceInCallResolver.jet new file mode 100644 index 00000000000..952ac6c3dbe --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/WrongTraceInCallResolver.jet @@ -0,0 +1,9 @@ +open class Foo {} +open class Bar {} + +fun <T : Bar, T1> foo(x : Int) {} +fun <T1, T : Foo> foo(x : Long) {} + +fun f(): Unit { + foo<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>(1) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/kt251.jet b/idea/testData/checkerWithErrorTypes/full/regression/kt251.jet new file mode 100644 index 00000000000..bfbc0784224 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/kt251.jet @@ -0,0 +1,33 @@ +class A() { + var x: Int = 0 + get() = <!TYPE_MISMATCH!>"s"<!> + set(value: <!WRONG_SETTER_PARAMETER_TYPE!>String<!>) { + $x = <!TYPE_MISMATCH!>value<!> + } + val y: Int + get(): <!WRONG_GETTER_RETURN_TYPE!>String<!> = "s" + val z: Int + get() { + return <!TYPE_MISMATCH!>"s"<!> + } + + var a: Any = 1 + set(v: <!WRONG_SETTER_PARAMETER_TYPE!>String<!>) { + $a = v + } + val b: Int + get(): <!WRONG_GETTER_RETURN_TYPE!>Any<!> = "s" + val c: Int + get() { + return 1 + } + val d = 1 + get() { + return $d + } + val e = 1 + get(): <!WRONG_GETTER_RETURN_TYPE!>String<!> { + return <!TYPE_MISMATCH!>$e<!> + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/full/regression/kt303.jet b/idea/testData/checkerWithErrorTypes/full/regression/kt303.jet new file mode 100644 index 00000000000..ed38edc0bf0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/regression/kt303.jet @@ -0,0 +1,11 @@ +// KT-303 Stack overflow on a cyclic class hierarchy + +open class Foo() : <!CYCLIC_INHERITANCE_HIERARCHY!>Bar<!>() { + val a : Int = 1 +} + +open class Bar() : <!CYCLIC_INHERITANCE_HIERARCHY!>Foo<!>() { + +} + +val x : Int = <!TYPE_MISMATCH!>Foo()<!> \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Abstract.jet b/idea/testData/checkerWithErrorTypes/quick/Abstract.jet index e30dabbd6ab..113ff0a34d6 100644 --- a/idea/testData/checkerWithErrorTypes/quick/Abstract.jet +++ b/idea/testData/checkerWithErrorTypes/quick/Abstract.jet @@ -19,7 +19,7 @@ class MyClass() { val e: Int get() = a val e1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = a - <!ABSTRACT_PROPERTY_IN_NN_ABSTRACT_CLASS!>abstract<!> val e2: Int get() = a + <!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val e2: Int get() = a <!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val e3: Int = 0; get() = a //methods diff --git a/idea/testData/checkerWithErrorTypes/quick/AnonymousInitializers.jet b/idea/testData/checkerWithErrorTypes/quick/AnonymousInitializers.jet new file mode 100644 index 00000000000..955798a7a9c --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/AnonymousInitializers.jet @@ -0,0 +1,34 @@ +class NoC { + <!ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR!>{ + + }<!> + + val a : Int get() = 1 + + <!ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR!>{ + + }<!> +} + +class WithC() { + val x : Int + { + $x = 1 + <!UNRESOLVED_REFERENCE!>$y<!> = 2 + val b = x + + } + + val a : Int get() = 1 + + { + val z = <!UNRESOLVED_REFERENCE!>b<!> + val zz = x + val zzz = <!NO_BACKING_FIELD!>$a<!> + } + + this(a : Int) : this() { + val b = x + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/BinaryCallsOnNullableValues.jet b/idea/testData/checkerWithErrorTypes/quick/BinaryCallsOnNullableValues.jet new file mode 100644 index 00000000000..86d34c881be --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/BinaryCallsOnNullableValues.jet @@ -0,0 +1,41 @@ +class A() { + fun equals(a : Any?) : Boolean = false +} + +class B() { + fun equals(a : Any?) : Boolean? = false +} + +class C() { + fun equals(a : Any?) : Int = 0 +} + +fun f(): Unit { + var x: Int? = 1 + x = 1 + x <!UNSAFE_INFIX_CALL!>+<!> 1 + x <!UNSAFE_INFIX_CALL!>plus<!> 1 + x <!UNSAFE_INFIX_CALL!><<!> 1 + x <!UNSAFE_INFIX_CALL!>+=<!> 1 + + x == 1 + x != 1 + + <!EQUALITY_NOT_APPLICABLE!>A() == 1<!> + B() <!RESULT_TYPE_MISMATCH!>==<!> 1 + C() <!RESULT_TYPE_MISMATCH!>==<!> 1 + + <!EQUALITY_NOT_APPLICABLE!>x === "1"<!> + <!EQUALITY_NOT_APPLICABLE!>x !== "1"<!> + + x === 1 + x !== 1 + + x<!UNSAFE_INFIX_CALL!>..<!>2 + <!TYPE_MISMATCH!>x<!> in 1..2 + + val y : Boolean? = true + false || <!TYPE_MISMATCH!>y<!> + <!TYPE_MISMATCH!>y<!> && true + <!TYPE_MISMATCH!>y<!> && <!TYPE_MISMATCH!>1<!> +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Bounds.jet b/idea/testData/checkerWithErrorTypes/quick/Bounds.jet new file mode 100644 index 00000000000..48eea1e3d6e --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Bounds.jet @@ -0,0 +1,40 @@ +namespace boundsWithSubstitutors { + open class A<T> + class B<X : A<X>>() + + class C : A<C> + + val a = B<C>() + val a1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>() + + class X<A, B : A>() + + val b = X<Any, X<A<C>, C>> + val b0 = X<Any, <!UPPER_BOUND_VIOLATED!>Any?<!>> + val b1 = X<Any, X<A<C>, <!UPPER_BOUND_VIOLATED!>String<!>>> + +} + + open class A {} + open class B<T : A>() + + abstract class C<T : B<<!UPPER_BOUND_VIOLATED!>Int<!>>, X : fun (B<<!UPPER_BOUND_VIOLATED!>Char<!>>) : (B<<!UPPER_BOUND_VIOLATED!>Any<!>>, B<A>)>() : B<<!UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED!>Any<!>>() { // 2 errors + val a = B<<!UPPER_BOUND_VIOLATED!>Char<!>>() // error + + abstract val x : fun (B<<!UPPER_BOUND_VIOLATED!>Char<!>>) : B<<!UPPER_BOUND_VIOLATED!>Any<!>> + } + + +fun test() { + foo<<!UPPER_BOUND_VIOLATED!>Int?<!>>() + foo<Int>() + bar<Int?>() + bar<Int>() + bar<<!UPPER_BOUND_VIOLATED!>Double?<!>>() + bar<<!UPPER_BOUND_VIOLATED!>Double<!>>() + 1.buzz<<!UPPER_BOUND_VIOLATED!>Double<!>>() +} + +fun foo<T : Any>() {} +fun bar<T : Int?>() {} +fun <T : <!FINAL_UPPER_BOUND!>Int<!>> Int.buzz() : Unit {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/BreakContinue.jet b/idea/testData/checkerWithErrorTypes/quick/BreakContinue.jet new file mode 100644 index 00000000000..2bf691799e0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/BreakContinue.jet @@ -0,0 +1,28 @@ +class C { + + fun f (a : Boolean, b : Boolean) { + @b (while (true) + @a { + <!NOT_A_LOOP_LABEL!>break@f<!> + break + break@b + <!NOT_A_LOOP_LABEL!>break@a<!> + }) + + <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!> + + @b (while (true) + @a { + <!NOT_A_LOOP_LABEL!>continue@f<!> + continue + continue@b + <!NOT_A_LOOP_LABEL!>continue@a<!> + }) + + <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!> + + <!NOT_A_LOOP_LABEL!>continue@f<!> + <!NOT_A_LOOP_LABEL!>break@f<!> + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Builders.jet b/idea/testData/checkerWithErrorTypes/quick/Builders.jet new file mode 100644 index 00000000000..0405b3fe398 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Builders.jet @@ -0,0 +1,121 @@ +import <!UNRESOLVED_REFERENCE!>java<!>.util.* + +namespace html { + + abstract class Factory<T> { + abstract fun create() : T + } + + abstract class Element + + class TextElement(val text : String) : Element + + abstract class Tag(val name : String) : Element { + val children = ArrayList<Element>() + val attributes = HashMap<String, String>() + + protected fun initTag<T : Element>(init : fun T.() : Unit) : T + where class object T : Factory<T>{ + val tag = T.create() + tag.init() + children.add(tag) + return tag + } + } + + abstract class TagWithText(name : String) : Tag(name) { + fun String.plus() { + children.add(<!OVERLOAD_RESOLUTION_AMBIGUITY!>TextElement(this)<!>) + } + } + + class HTML() : TagWithText("html") { + class object : Factory<HTML> { + override fun create() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>HTML()<!> + } + + fun head(init : fun Head.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<Head>(init)<!> + + fun body(init : fun Body.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<Body>(init)<!> + } + + class Head() : TagWithText("head") { + class object : Factory<Head> { + override fun create() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>Head()<!> + } + + fun title(init : fun Title.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<Title>(init)<!> + } + + class Title() : TagWithText("title") + + abstract class BodyTag(name : String) : TagWithText(name) { + } + + class Body() : BodyTag("body") { + class object : Factory<Body> { + override fun create() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>Body()<!> + } + + fun b(init : fun B.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<B>(init)<!> + fun p(init : fun P.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<P>(init)<!> + fun h1(init : fun H1.() : Unit) = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<H1>(init)<!> + fun a(href : String, init : fun A.() : Unit) { + val a = <!OVERLOAD_RESOLUTION_AMBIGUITY!>initTag<A>(init)<!> + a.href = href + } + } + + class B() : BodyTag("b") + class P() : BodyTag("p") + class H1() : BodyTag("h1") + class A() : BodyTag("a") { + var href : String + get() = attributes["href"] + set(value) { attributes["href"] = value } + } + + fun Map<String, String>.set(key : String, value : String) = this.put(key, value) + + fun html(init : fun HTML.() : Unit) : HTML { + val html = <!OVERLOAD_RESOLUTION_AMBIGUITY!>HTML()<!> + html.init() + return html + } + +} + +namespace foo { + +import html.* + +fun result(args : Array<String>) = + <!OVERLOAD_RESOLUTION_AMBIGUITY!>html { + <!OVERLOAD_RESOLUTION_AMBIGUITY!>head { + <!OVERLOAD_RESOLUTION_AMBIGUITY!>title {<!NO_VALUE_FOR_PARAMETER!>+<!>"XML encoding with Groovy"}<!> + }<!> + <!OVERLOAD_RESOLUTION_AMBIGUITY!>body { + <!OVERLOAD_RESOLUTION_AMBIGUITY!>h1 {<!NO_VALUE_FOR_PARAMETER!>+<!>"XML encoding with Groovy"}<!> + <!OVERLOAD_RESOLUTION_AMBIGUITY!>p {<!NO_VALUE_FOR_PARAMETER!>+<!>"this format can be used as an alternative markup to XML"}<!> + + // an element with attributes and text content + <!OVERLOAD_RESOLUTION_AMBIGUITY!>a(href = "http://groovy.codehaus.org") {<!NO_VALUE_FOR_PARAMETER!>+<!>"Groovy"}<!> + + // mixed content + <!OVERLOAD_RESOLUTION_AMBIGUITY!>p { + <!NO_VALUE_FOR_PARAMETER!>+<!>"This is some" + <!OVERLOAD_RESOLUTION_AMBIGUITY!>b {<!NO_VALUE_FOR_PARAMETER!>+<!>"mixed"}<!> + <!NO_VALUE_FOR_PARAMETER!>+<!>"text. For more see the" + <!OVERLOAD_RESOLUTION_AMBIGUITY!>a(href = "http://groovy.codehaus.org") {<!NO_VALUE_FOR_PARAMETER!>+<!>"Groovy"}<!> + <!NO_VALUE_FOR_PARAMETER!>+<!>"project" + }<!> + <!OVERLOAD_RESOLUTION_AMBIGUITY!>p {<!NO_VALUE_FOR_PARAMETER!>+<!>"some text"}<!> + + // content generated by + <!OVERLOAD_RESOLUTION_AMBIGUITY!>p { + for (arg in args) + <!NO_VALUE_FOR_PARAMETER!>+<!>arg + }<!> + }<!> + }<!> +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Casts.jet b/idea/testData/checkerWithErrorTypes/quick/Casts.jet new file mode 100644 index 00000000000..163619fd4d0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Casts.jet @@ -0,0 +1,16 @@ +fun test() : Unit { + var x : Int? = 0 + var y : Int = 0 + + x : Int? + y : Int + x as Int : Int + y <!USELESS_CAST!>as<!> Int : Int + x <!USELESS_CAST!>as<!> Int? : Int? + y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int? : Int? + x as? Int : Int? + y <!USELESS_CAST!>as?<!> Int : Int? + x <!USELESS_CAST!>as?<!> Int? : Int? + y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as?<!> Int? : Int? + () +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/ClassObjects.jet b/idea/testData/checkerWithErrorTypes/quick/ClassObjects.jet new file mode 100644 index 00000000000..9937c5ab453 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/ClassObjects.jet @@ -0,0 +1,30 @@ +namespace Jet86 + +class A { + class object { + val x = 1 + } + <!MANY_CLASS_OBJECTS!>class object { // error + val x = 1 + }<!> +} + +class B() { + val x = 12 +} + +object b { + <!CLASS_OBJECT_NOT_ALLOWED!>class object { + val x = 1 + }<!> // error +} + +val a = A.x +val c = <!NO_CLASS_OBJECT!>B<!>.x +val d = b.<!UNRESOLVED_REFERENCE!>x<!> + +val s = <!UNRESOLVED_REFERENCE!>System<!> // error +fun test() { + <!UNRESOLVED_REFERENCE!>System<!>.out<!UNNECESSARY_SAFE_CALL!>?.<!>println() + <!UNRESOLVED_REFERENCE!>java<!>.lang.System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Constants.jet b/idea/testData/checkerWithErrorTypes/quick/Constants.jet new file mode 100644 index 00000000000..cc908e189f0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Constants.jet @@ -0,0 +1,8 @@ +fun test() { + 1 : Byte + 1 : Int + <!TYPE_MISMATCH, TYPE_MISMATCH!>1<!> : Double + 1 <!USELESS_CAST!>as<!> Byte + 1 <!USELESS_CAST!>as<!> Int + <!ERROR_COMPILE_TIME_VALUE!>1<!> <!CAST_NEVER_SUCCEEDS!>as<!> Double +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/CyclicHierarchy.jet b/idea/testData/checkerWithErrorTypes/quick/CyclicHierarchy.jet new file mode 100644 index 00000000000..ff99017a12b --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/CyclicHierarchy.jet @@ -0,0 +1,30 @@ +open trait A { + fun foo() {} +} +open trait B : A, <!CYCLIC_INHERITANCE_HIERARCHY!>E<!> {} +open trait C : B {} +open trait D : <!CYCLIC_INHERITANCE_HIERARCHY!>B<!> {} +open trait E : <!CYCLIC_INHERITANCE_HIERARCHY!>F<!> {} +open trait F : <!CYCLIC_INHERITANCE_HIERARCHY!>D<!>, C {} +open trait G : F {} +open trait H : F {} + +val a : A? = null +val b : B? = null +val c : C? = null +val d : D? = null +val e : E? = null +val f : F? = null +val g : G? = null +val h : H? = null + +fun test() { + a?.foo() + b?.foo() + c?.foo() + d?.foo() + e?.<!UNRESOLVED_REFERENCE!>foo<!>() + f?.foo() + g?.foo() + h?.foo() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Enums.jet b/idea/testData/checkerWithErrorTypes/quick/Enums.jet new file mode 100644 index 00000000000..0ef400fda22 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Enums.jet @@ -0,0 +1,10 @@ +enum class List<out T>(val size : Int) { + Nil : List<Nothing>(0) { + val a = 1 + } + Cons<out T>(val head : T, val tail : List<T>) : List<T>(tail.size + 1) + +} + +val foo = List.Nil +val foo1 = foo.a \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/ExtensionFunctions.jet b/idea/testData/checkerWithErrorTypes/quick/ExtensionFunctions.jet new file mode 100644 index 00000000000..50544c581c8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/ExtensionFunctions.jet @@ -0,0 +1,71 @@ +fun Int?.optint() : Unit {} +val Int?.optval : Unit = () + +fun <T, E> T.foo(x : E, y : A) : T { + y.plus(1) + y plus 1 + y + 1.0 + + this<!UNNECESSARY_SAFE_CALL!>?.<!>minus<T>(this) + + return this +} + +class A + +fun A.plus(a : Any) { + + 1.foo() + true.<!NONE_APPLICABLE!>foo()<!> + + 1 +} + +fun A.plus(a : Int) { + 1 +} + +fun <T> T.minus(t : T) : Int = 1 + +fun test() { + val y = 1.abs +} +val Int.abs : Int + get() = if (this > 0) this else -this; + +val <T> T.<!MUST_BE_INITIALIZED!>foo<!> : T + +fun Int.foo() = this + +namespace null_safety { + + fun parse(cmd: String): Command? { return null } + class Command() { + // fun equals(other : Any?) : Boolean + val foo : Int = 0 + } + + fun Any.equals(other : Any?) : Boolean = true + fun Any?.equals1(other : Any?) : Boolean = true + fun Any.equals2(other : Any?) : Boolean = true + + fun main(args: Array<String>) { + + <!UNRESOLVED_REFERENCE!>System<!>.out<!UNNECESSARY_SAFE_CALL!>?.<!>print(1) + + val command = parse("") + + command<!UNSAFE_CALL!>.<!>foo + + command.equals(null) + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null) + command.equals1(null) + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals1(null) + + val c = Command() + c<!UNNECESSARY_SAFE_CALL!>?.<!>equals2(null) + + if (command == null) 1 + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/ForRangeConventions.jet b/idea/testData/checkerWithErrorTypes/quick/ForRangeConventions.jet new file mode 100644 index 00000000000..61c797c6282 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/ForRangeConventions.jet @@ -0,0 +1,80 @@ +import <!UNRESOLVED_REFERENCE!>java<!>.util.*; + +class NotRange1() { + +} + +abstract class NotRange2() { + abstract fun iterator() : Unit +} + +abstract class ImproperIterator1 { + abstract fun hasNext() : Boolean +} + +abstract class NotRange3() { + abstract fun iterator() : ImproperIterator1 +} + +abstract class ImproperIterator2 { + abstract fun next() : Boolean +} + +abstract class NotRange4() { + abstract fun iterator() : ImproperIterator2 +} + +abstract class ImproperIterator3 { + abstract fun hasNext() : Int + abstract fun next() : Int +} + +abstract class NotRange5() { + abstract fun iterator() : ImproperIterator3 +} + +abstract class AmbiguousHasNextIterator { + abstract fun hasNext() : Boolean + val hasNext : Boolean get() = false + abstract fun next() : Int +} + +abstract class NotRange6() { + abstract fun iterator() : AmbiguousHasNextIterator +} + +abstract class ImproperIterator4 { + val hasNext : Int get() = 1 + abstract fun next() : Int +} + +abstract class NotRange7() { + abstract fun iterator() : ImproperIterator3 +} + +abstract class GoodIterator { + abstract fun hasNext() : Boolean + abstract fun next() : Int +} + +abstract class Range0() { + abstract fun iterator() : GoodIterator +} + +abstract class Range1() { + abstract fun iterator() : Iterator<Int> +} + +fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRange4: NotRange4, notRange5: NotRange5, notRange6: NotRange6, notRange7: NotRange7, range0: Range0, range1: Range1) { + for (i in <!ITERATOR_MISSING!>notRange1<!>); + for (i in <!HAS_NEXT_MISSING, NEXT_MISSING!>notRange2<!>); + for (i in <!NEXT_MISSING!>notRange3<!>); + for (i in <!HAS_NEXT_MISSING!>notRange4<!>); + for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange5<!>); + for (i in <!HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY!>notRange6<!>); + for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange7<!>); + for (i in range0); + for (i in range1); + + for (i in (ArrayList<Int>() : List<Int>)); +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/FunctionReturnTypes.jet b/idea/testData/checkerWithErrorTypes/quick/FunctionReturnTypes.jet new file mode 100644 index 00000000000..428c84ab0f1 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/FunctionReturnTypes.jet @@ -0,0 +1,166 @@ +fun none() {} + +fun unitEmptyInfer() {} +fun unitEmpty() : Unit {} +fun unitEmptyReturn() : Unit {return} +fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>} +fun unitUnitReturn() : Unit {return ()} +fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!>} +fun test2() : Any = @a {return@a 1} +fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> } + +fun bbb() { + return <!TYPE_MISMATCH!>1<!> +} + +fun foo(expr: <!UNRESOLVED_REFERENCE!>StringBuilder<!>): Int { + val c = 'a' + when(c) { + 0.chr => throw <!UNRESOLVED_REFERENCE!>Exception<!>("zero") + else => throw <!UNRESOLVED_REFERENCE!>Exception<!>("nonzero" + c) + } +} + + +fun unitShort() : Unit = () +fun unitShortConv() : Unit = <!TYPE_MISMATCH!>1<!> +fun unitShortNull() : Unit = <!TYPE_MISMATCH!>null<!> + +fun intEmpty() : Int <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> +fun intShortInfer() = 1 +fun intShort() : Int = 1 +//fun intBlockInfer() {1} +fun intBlock() : Int {return 1} +fun intBlock() : Int {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1<!>} + +fun intString(): Int = <!TYPE_MISMATCH!>"s"<!> +fun intFunctionLiteral(): Int = <!TYPE_MISMATCH!>{ 10 }<!> + +fun blockReturnUnitMismatch() : Int {<!RETURN_TYPE_MISMATCH!>return<!>} +fun blockReturnValueTypeMismatch() : Int {return <!ERROR_COMPILE_TIME_VALUE!>3.4<!>} +fun blockReturnValueTypeMatch() : Int {return 1} +fun blockReturnValueTypeMismatchUnit() : Int {return <!TYPE_MISMATCH!>()<!>} + +fun blockAndAndMismatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true && false<!> +} +fun blockAndAndMismatch() : Int { + return <!TYPE_MISMATCH!>true && false<!> +} +fun blockAndAndMismatch() : Int { + <!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) && (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!> +} + +fun blockAndAndMismatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true || false<!> +} +fun blockAndAndMismatch() : Int { + return <!TYPE_MISMATCH!>true || false<!> +} +fun blockAndAndMismatch() : Int { + <!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) || (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!> +} +fun blockReturnValueTypeMatch() : Int { + return if (1 > 2) <!ERROR_COMPILE_TIME_VALUE!>1.0<!> else <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) 1<!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) else 1<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + else return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> + return <!ERROR_COMPILE_TIME_VALUE!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!> + else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>2.0<!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + 1.0 + else 2.0 + return 1 +} +fun blockReturnValueTypeMatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2) + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!> +} +fun blockReturnValueTypeMatch() : Int { + return <!TYPE_MISMATCH!>if (1 > 2) + 1<!> +} +fun blockReturnValueTypeMatch() : Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2) + else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!> +} +fun blockReturnValueTypeMatch() : Int { + if (1 > 2) + return 1 + else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!> +} +fun blockNoReturnIfValDeclaration(): Int { + <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val x = 1<!> +} +fun blockNoReturnIfEmptyIf(): Int { + if (1 < 2) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> +} +fun blockNoReturnIfUnitInOneBranch(): Int { + if (1 < 2) { + return 1 + } else { + if (3 < 4) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{ + }<!> else { + return 2 + } + } +} +fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!> +fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2 + +val a = <!RETURN_NOT_ALLOWED!>return 1<!> + +class A() { + this(a : Int) : this() { + if (a == 1) + return + return <!TYPE_MISMATCH!>1<!> + } + +} +fun illegalConstantBody(): Int = <!TYPE_MISMATCH!>"s"<!> +fun illegalConstantBlock(): String { + return <!ERROR_COMPILE_TIME_VALUE!>1<!> +} +fun illegalIfBody(): Int = + if (1 < 2) <!ERROR_COMPILE_TIME_VALUE!>'a'<!> else { <!ERROR_COMPILE_TIME_VALUE!>1.0<!> } +fun illegalIfBlock(): Boolean { + if (1 < 2) + return false + else { return <!ERROR_COMPILE_TIME_VALUE!>1<!> } +} +fun illegalReturnIf(): Char { + return if (1 < 2) 'a' else { <!ERROR_COMPILE_TIME_VALUE!>1<!> } +} + +fun returnNothing(): Nothing { + throw 1 +} +fun f(): Int { + if (1 < 2) { return 1 } else returnNothing() +} + +fun f(): Int = if (1 < 2) 1 else returnNothing() \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/GenericArgumentConsistency.jet b/idea/testData/checkerWithErrorTypes/quick/GenericArgumentConsistency.jet new file mode 100644 index 00000000000..fafd2cf98c8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/GenericArgumentConsistency.jet @@ -0,0 +1,42 @@ +trait A<in T> {} +trait B<T> : A<Int> {} +trait C<T> : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>B<T>, A<T><!> {} +trait C1<T> : B<T>, A<Any> {} +trait D : <!INCONSISTENT_TYPE_PARAMETER_VALUES, INCONSISTENT_TYPE_PARAMETER_VALUES!>C<Boolean>, B<Double><!>{} + +trait A1<out T> {} +trait B1 : A1<Int> {} +trait B2 : A1<Any>, B1 {} + +trait BA1<T> {} +trait BB1 : BA1<Int> {} +trait BB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>BA1<Any>, BB1<!> {} + + +namespace x { + trait AA1<out T> {} + trait AB1 : AA1<Int> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : AA1<Number>, AB1, AB3 {} +} + +namespace x2 { + trait AA1<out T> {} + trait AB1 : AA1<Any> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {} +} + +namespace x3 { + trait AA1<in T> {} + trait AB1 : AA1<Any> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : AA1<Number>, AB1, AB3 {} +} + +namespace sx2 { + trait AA1<in T> {} + trait AB1 : AA1<Int> {} + trait AB3 : AA1<Comparable<Int>> {} + trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {} +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/IncDec.jet b/idea/testData/checkerWithErrorTypes/quick/IncDec.jet new file mode 100644 index 00000000000..5b7143f3eef --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/IncDec.jet @@ -0,0 +1,46 @@ +class IncDec() { + fun inc() : IncDec = this + fun dec() : IncDec = this +} + +fun testIncDec() { + var x = IncDec() + x++ + ++x + x-- + --x + x = x++ + x = x-- + x = ++x + x = --x +} + +class WrongIncDec() { + fun inc() : Int = 1 + fun dec() : Int = 1 +} + +fun testWrongIncDec() { + var x = WrongIncDec() + x<!RESULT_TYPE_MISMATCH!>++<!> + <!RESULT_TYPE_MISMATCH!>++<!>x + x<!RESULT_TYPE_MISMATCH!>--<!> + <!RESULT_TYPE_MISMATCH!>--<!>x +} + +class UnitIncDec() { + fun inc() : Unit {} + fun dec() : Unit {} +} + +fun testUnitIncDec() { + var x = UnitIncDec() + x++ + ++x + x-- + --x + x = <!TYPE_MISMATCH!>x++<!> + x = <!TYPE_MISMATCH!>x--<!> + x = <!TYPE_MISMATCH!>++x<!> + x = <!TYPE_MISMATCH!>--x<!> +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/IsExpressions.jet b/idea/testData/checkerWithErrorTypes/quick/IsExpressions.jet new file mode 100644 index 00000000000..960f3711e37 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/IsExpressions.jet @@ -0,0 +1,7 @@ +fun test() { + if (1 is Int) { + if (1 is <!INCOMPATIBLE_TYPES!>Boolean<!>) { + + } + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/MultipleBounds.jet b/idea/testData/checkerWithErrorTypes/quick/MultipleBounds.jet new file mode 100644 index 00000000000..942d7f1630f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/MultipleBounds.jet @@ -0,0 +1,72 @@ +namespace Jet87 + +open class A() { + fun foo() : Int = 1 +} + +trait B { + fun bar() : Double = 1.0; +} + +class C() : A(), B + +class D() { + class object : A(), B {} +} + +class Test1<T : A>() + where + T : B, + <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, // error + class object T : A, + class object T : B, + class object <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T + { + + fun test(t : T) { + T.foo() + T.bar() + t.foo() + t.bar() + } +} + +fun test() { + Test1<<!UPPER_BOUND_VIOLATED!>B<!>>() + Test1<<!UPPER_BOUND_VIOLATED!>A<!>>() + Test1<C>() +} + +class Foo() {} + +class Bar<T : <!FINAL_UPPER_BOUND!>Foo<!>> + +class Buzz<T> where T : <!FINAL_UPPER_BOUND!>Bar<<!UPPER_BOUND_VIOLATED!>Int<!>><!>, T : <!UNRESOLVED_REFERENCE!>nioho<!> + +class X<T : <!FINAL_UPPER_BOUND!>Foo<!>> +class Y<<!CONFLICTING_UPPER_BOUNDS!>T<!> : <!FINAL_UPPER_BOUND!>Foo<!>> where T : <!FINAL_UPPER_BOUND!>Bar<Foo><!> + +fun <T : A> test2(t : T) + where + T : B, + <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, + class object <!NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER!>B<!> : T, + class object T : B, + class object T : A +{ + T.foo() + T.bar() + t.foo() + t.bar() +} + +val t1 = test2<<!UPPER_BOUND_VIOLATED!>A<!>>(A()) +val t2 = test2<<!UPPER_BOUND_VIOLATED!>B<!>>(C()) +val t3 = test2<C>(C()) + +class Test<<!CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS!>T<!>> + where + class object T : <!FINAL_CLASS_OBJECT_UPPER_BOUND!>Foo<!>, + class object T : A {} + +val <T, B : T> x : Int = 0 \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/NamespaceAsExpression.jet b/idea/testData/checkerWithErrorTypes/quick/NamespaceAsExpression.jet new file mode 100644 index 00000000000..4ef4bd01ced --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/NamespaceAsExpression.jet @@ -0,0 +1,8 @@ +namespace root + +namespace a { + +} + +val x = <!EXPRESSION_EXPECTED_NAMESPACE_FOUND, UNRESOLVED_REFERENCE!>a<!> +val y2 = <!NAMESPACE_IS_NOT_AN_EXPRESSION!>namespace<!> \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/NamespaceQualified.jet b/idea/testData/checkerWithErrorTypes/quick/NamespaceQualified.jet new file mode 100644 index 00000000000..1b280e7a644 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/NamespaceQualified.jet @@ -0,0 +1,63 @@ +namespace foobar + +namespace a { + import <!UNRESOLVED_REFERENCE!>java<!>.* + + val a : <!UNRESOLVED_REFERENCE!>util<!>.List<Int>? = null + val a1 : <!UNRESOLVED_REFERENCE!>List<!><Int>? = null + +} + +abstract class Foo<T>() { + abstract val x : T<Int> +} + +namespace a { + import <!UNRESOLVED_REFERENCE!>java<!>.util.* + + val b : List<Int>? = a + val b1 : util.List<Int>? = a +} + +val x1 = a.a + +val y1 = a.b + + +///////////////////////////////////////////////////////////////////////// + +fun done<O>(result : O) : Iteratee<Any?, O> = StrangeIterateeImpl<Any?, O>(result) + +abstract class Iteratee<in I, out O> { + abstract fun process(item : I) : Iteratee<I, O> + abstract val isDone : Boolean + abstract val result : O + abstract fun done() : O +} + +class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> { + override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj) + override val isDone = true + override val result = obj + override fun done() = obj +} + +abstract class Sum() : Iteratee<Int, Int> { + override fun process(item : Int) : Iteratee<Int, Int> { + return foobar.done<Int>(item); + } + abstract override val isDone : Boolean + abstract override val result : Int + abstract override fun done() : Int +} + +abstract class Collection<E> : Iterable<E> { + fun iterate<O>(iteratee : Iteratee<E, O>) : O { + for (x in this) { + val it = iteratee.process(x) + if (it.isDone) return it.result + iteratee = it + } + return iteratee.done() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Nullability.jet b/idea/testData/checkerWithErrorTypes/quick/Nullability.jet new file mode 100644 index 00000000000..d803a36e15a --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Nullability.jet @@ -0,0 +1,280 @@ +fun test() { + val a : Int? = 0 + if (a != null) { + a.plus(1) + } + else { + a?.plus(1) + } + + val out : <!UNRESOLVED_REFERENCE!>java<!>.io.PrintStream? = null//= System.out + val ins = <!UNRESOLVED_REFERENCE!>System<!>.`in` + + out?.println() + ins<!UNNECESSARY_SAFE_CALL!>?.<!>read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins<!UNNECESSARY_SAFE_CALL!>?.<!>read(); + out.println(); + } + + if (out == null || out.println(0) == ()) { + out?.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == ()) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out != null && out.println() == ()) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == ()) { + out?.println(2); + } + else { + out?.println(3) + } + + out?.println() + ins<!UNNECESSARY_SAFE_CALL!>?.<!>read() + + if (ins != null) { + ins.read() + out?.println() + if (out != null) { + ins.read(); + out.println(); + } + } + + if (out != null && ins != null) { + ins.read(); + out.println(); + } + + if (out == null) { + out?.println() + } else { + out.println() + } + + if (out != null && ins != null || out != null) { + ins<!UNNECESSARY_SAFE_CALL!>?.<!>read(); + out.println(); + } + + if (out == null || out.println(0) == ()) { + out?.println(1) + } + else { + out.println(2) + } + + if (out != null && out.println() == ()) { + out.println(); + } + else { + out?.println(); + } + + if (out == null || out != null && out.println() == ()) { + out?.println(); + } + else { + out.println(); + } + + if (1 == 2 || out != null && out.println(1) == ()) { + out?.println(2); + } + else { + out?.println(3) + } + + if (1 > 2) { + if (out == null) return; + out.println(); + } + out?.println(); + + while (out != null) { + out.println(); + } + out?.println(); + + while (out == null) { + out?.println(); + } + out.println() + +} + + +fun f(out : String?) { + out?.get(0) + if (out != null) else return; + out.get(0) +} + +fun f1(out : String?) { + out?.get(0) + if (out != null) else { + 1 + 2 + return; + } + out.get(0) +} + +fun f2(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + out.get(0) +} + +fun f3(out : String?) { + out?.get(0) + if (out == null) { + 1 + 2 + return; + } + else { + 1 + 2 + } + out.get(0) +} + +fun f4(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + s?.get(0) + } + s.get(0) +} + +fun f5(s : String?) { + s?.get(0) + while (1 < 2 && s != null) { + s.get(0) + } + s?.get(0) + while (s == null || 1 < 2) { + if (1 > 2) break + s?.get(0) + } + s?.get(0); +} + +fun f6(s : String?) { + s?.get(0) + do { + s?.get(0) + if (1 < 2) break; + } while (s == null) + s?.get(0) + do { + s?.get(0) + } while (s == null) + s.get(0) +} + +fun f7(s : String?, t : String?) { + s?.get(0) + if (!(s == null)) { + s.get(0) + } + s?.get(0) + if (!(s != null)) { + s?.get(0) + } + else { + s.get(0) + } + s?.get(0) + if (!!(s != null)) { + s.get(0) + } + else { + s?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null || t == null)) { + s.get(0) + t.get(0) + } + else { + s?.get(0) + t?.get(0) + } + s?.get(0) + t?.get(0) + if (!(s == null && s == null)) { + s.get(0) + t?.get(0) + } + else { + s?.get(0) + t?.get(0) + } +} + +fun f8(b : String?, a : String) { + b?.get(0) + if (b == a) { + b.get(0); + } + b?.get(0) + if (a == b) { + b.get(0) + } + if (a != b) { + b?.get(0) + } + else { + b.get(0) + } +} + +fun f9(a : Int?) : Int { + if (a != null) + return a + return 1 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Objects.jet b/idea/testData/checkerWithErrorTypes/quick/Objects.jet new file mode 100644 index 00000000000..378534ea4d3 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Objects.jet @@ -0,0 +1,83 @@ +namespace toplevelObjectDeclarations { + open class Foo(y : Int) { + open fun foo() : Int = 1 + } + + class T : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> {} + + object A : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> { + val x : Int = 2 + + fun test() : Int { + return x + foo() + } + } + + object B : <!UNRESOLVED_REFERENCE!>A<!> {} + + val x = A.foo() + + val y = object : Foo(x) { + { + x + 12 + } + + override fun foo() : Int = 1 + } + + val z = y.foo() +} + +namespace nestedObejcts { + object A { + val b = B + val d = A.B.A + + object B { + val a = A + val e = B.A + + object A { + val a = A + val b = B + val x = nestedObejcts.A.B.A + val y = this<!AMBIGUOUS_LABEL!>@A<!> + } + } + + } + object B { + val b = B + val c = A.B + } + + val a = A + val b = B + val c = A.B + val d = A.B.A + val e = B.<!UNRESOLVED_REFERENCE!>A<!>.B +} + +namespace localObjects { + object A { + val x : Int = 0 + } + + open class Foo { + fun foo() : Int = 1 + } + + fun test() { + A.x + val b = object : Foo { + } + b.foo() + + object B { + fun foo() {} + } + B.foo() + } + + val bb = <!UNRESOLVED_REFERENCE!>B<!>.foo() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Override.jet b/idea/testData/checkerWithErrorTypes/quick/Override.jet new file mode 100644 index 00000000000..fecb1c72304 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Override.jet @@ -0,0 +1,76 @@ +namespace override + +namespace normal { + trait MyTrait { + fun foo() + } + + abstract class MyAbstractClass { + abstract fun bar() + } + + open class MyClass : MyTrait, MyAbstractClass { + override fun foo() {} + override fun bar() {} + } + + class MyChildClass : MyClass {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass2<!> : MyTrait, MyAbstractClass { + override fun foo() {} + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass3<!> : MyTrait, MyAbstractClass { + override fun bar() {} + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass4<!> : MyTrait, MyAbstractClass { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>() {} + <!NOTHING_TO_OVERRIDE!>override<!> fun other() {} + } + + class MyChildClass1 : MyClass { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>() {} + override fun bar() {} + } +} + +namespace generics { + trait MyTrait<T> { + fun foo(t: T) : T + } + + abstract class MyAbstractClass<T> { + abstract fun bar(t: T) : T + } + + open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T> { + override fun foo(t: T) = t + override fun bar(t: T) = t + } + + class MyChildClass : MyGenericClass<Int> {} + class MyChildClass1<T> : MyGenericClass<T> {} + class MyChildClass2<T> : MyGenericClass<T> { + fun <!VIRTUAL_METHOD_HIDDEN!>foo<!>(t: T) = t + override fun bar(t: T) = t + } + + open class MyClass : MyTrait<Int>, MyAbstractClass<String> { + override fun foo(i: Int) = i + override fun bar(s: String) = s + } + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T> {} + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R> : MyTrait<T>, MyAbstractClass<R> { + <!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r + } + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String> {} + + class <!ABSTRACT_METHOD_NOT_IMPLEMENTED!>MyIllegalClass2<!><T> : MyTrait<Int>, MyAbstractClass<Int> { + fun foo(t: T) = t + fun bar(t: T) = t + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/PrimaryConstructors.jet b/idea/testData/checkerWithErrorTypes/quick/PrimaryConstructors.jet new file mode 100644 index 00000000000..8756860955f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/PrimaryConstructors.jet @@ -0,0 +1,14 @@ +class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>X<!> { + val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int +} + +open class Y() { + val x : Int = 2 +} + +class Y1 { + val x : Int get() = 1 +} + +class Z : Y<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!> { +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/ProjectionsInSupertypes.jet b/idea/testData/checkerWithErrorTypes/quick/ProjectionsInSupertypes.jet new file mode 100644 index 00000000000..c02bb72b6a2 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/ProjectionsInSupertypes.jet @@ -0,0 +1,6 @@ +trait A<T> {} +trait B<T> {} +trait C<T> {} +trait D<T> {} + +trait Test : A<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>in<!> Int>, B<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>out<!> Int>, C<<!PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE!>*<!>><!NULLABLE_SUPERTYPE!>?<!><!NULLABLE_SUPERTYPE!>?<!><!NULLABLE_SUPERTYPE!>?<!>, D<Int> {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Properties.jet b/idea/testData/checkerWithErrorTypes/quick/Properties.jet new file mode 100644 index 00000000000..a20950ac88a --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Properties.jet @@ -0,0 +1,28 @@ +var x : Int = 1 + x + get() : Int = 1 + set(<!REF_SETTER_PARAMETER!>ref<!> value : <!WRONG_SETTER_PARAMETER_TYPE!>Long<!>) { + $x = value.int + $x = <!TYPE_MISMATCH!>1.lng<!> + } + + val xx : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1 + x<!> + get() : Int = 1 + <!VAL_WITH_SETTER!>set(value : Long) {}<!> + + val p : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!> + get() = 1 + +class Test() { + var a : Int = 111 + var b : Int get() = <!UNRESOLVED_REFERENCE!>$a<!>; set(x) {a = x; <!UNRESOLVED_REFERENCE!>$a<!> = x} + + this(i : Int) : this() { + <!NO_BACKING_FIELD!>$b<!> = $a + $a = <!NO_BACKING_FIELD!>$b<!> + a = <!NO_BACKING_FIELD!>$b<!> + } + fun f() { + <!UNRESOLVED_REFERENCE!>$b<!> = <!UNRESOLVED_REFERENCE!>$a<!> + a = <!UNRESOLVED_REFERENCE!>$b<!> + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/QualifiedExpressions.jet b/idea/testData/checkerWithErrorTypes/quick/QualifiedExpressions.jet new file mode 100644 index 00000000000..67233fd840f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/QualifiedExpressions.jet @@ -0,0 +1,11 @@ +namespace qualified_expressions + +fun test(s: String?) { + val a: Int = <!TYPE_MISMATCH!>s?.length<!> + val b: Int? = s?.length + val c: Int = s?.length ?: -11 + val d: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!> + val e: String = <!TYPE_MISMATCH!>s?.length<!> ?: "empty" + val f: Int = s?.length ?: b ?: 1 + val g: Int? = e? startsWith("s")?.length +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/QualifiedThis.jet b/idea/testData/checkerWithErrorTypes/quick/QualifiedThis.jet new file mode 100644 index 00000000000..33fdf5dd8f5 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/QualifiedThis.jet @@ -0,0 +1,41 @@ +class Dup { + fun Dup() : Unit { + this<!AMBIGUOUS_LABEL!>@Dup<!> + } +} + +class A() { + fun foo() : Unit { + this@A + this<!UNRESOLVED_REFERENCE!>@a<!> + this + } + + val x = this@A.foo() + val y = this.foo() + val z = foo() +} + +fun foo1() : Unit { + <!NO_THIS!>this<!> + this<!UNRESOLVED_REFERENCE!>@a<!> +} + +namespace closures { + class A(val a:Int) { + + class B() { + val x = this@B : B + val y = this@A : A + val z = this : B + val Int.xx = this : Int + fun Char.xx() : Any { + this : Char + val a = {Double.() => this : Double + this@xx : Char} + val b = @a{Double.() => this@a : Double + this@xx : Char} + val c = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char} + return (@a{Double.() => this@a : Double + this@xx : Char}) + } + } + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/RecursiveTypeInference.jet b/idea/testData/checkerWithErrorTypes/quick/RecursiveTypeInference.jet new file mode 100644 index 00000000000..11eb880a193 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/RecursiveTypeInference.jet @@ -0,0 +1,42 @@ +namespace a { + val foo = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun bar() = foo +} + +namespace b { + fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun bar() = foo() +} + +namespace c { + fun bazz() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> + + fun foo() = bazz() + + fun bar() = foo() +} + +namespace ok { + + namespace a { + val foo = bar() + + fun bar() : Int = foo + } + + namespace b { + fun foo() : Int = bar() + + fun bar() = foo() + } + + namespace c { + fun bazz() = bar() + + fun foo() : Int = bazz() + + fun bar() = foo() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/ResolveToJava.jet b/idea/testData/checkerWithErrorTypes/quick/ResolveToJava.jet new file mode 100644 index 00000000000..dacaa387022 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/ResolveToJava.jet @@ -0,0 +1,52 @@ +import <!UNRESOLVED_REFERENCE!>java<!>.* +import <!UNRESOLVED_REFERENCE!>util<!>.* +import <!UNRESOLVED_REFERENCE!>utils<!>.* + +import <!UNRESOLVED_REFERENCE!>java<!>.io.PrintStream +import <!UNRESOLVED_REFERENCE!>java<!>.lang.Comparable as Com + +val l : <!UNRESOLVED_REFERENCE!>List<!><in Int> = <!UNRESOLVED_REFERENCE!>ArrayList<!><Int>() + +fun test(l : <!UNRESOLVED_REFERENCE!>java<!>.util.List<Int>) { + val x : <!UNRESOLVED_REFERENCE!>java<!>.List + val y : <!UNRESOLVED_REFERENCE!>java<!>.util.List<Int> + val b : <!UNRESOLVED_REFERENCE!>java<!>.lang.Object + val a : <!UNRESOLVED_REFERENCE!>util<!>.List<Int> + val z : <!UNRESOLVED_REFERENCE!>java<!>.utils.List<Int> + + val f : <!UNRESOLVED_REFERENCE!>java<!>.io.File? = null + + <!UNRESOLVED_REFERENCE!>Collections<!>.emptyList + <!UNRESOLVED_REFERENCE!>Collections<!>.emptyList<Int> + <!UNRESOLVED_REFERENCE!>Collections<!>.emptyList<Int>() + <!UNRESOLVED_REFERENCE!>Collections<!>.emptyList() + + <!UNRESOLVED_REFERENCE!>Collections<!>.singleton<Int>(1) : <!UNRESOLVED_REFERENCE!>Set<!><Int>? + <!UNRESOLVED_REFERENCE!>Collections<!>.singleton<Int>(1.0) + + <!UNRESOLVED_REFERENCE!>List<!><Int> + + + val o = "sdf" <!USELESS_CAST!>as<!> <!UNRESOLVED_REFERENCE!>Object<!> + + try { + // ... + } + catch(e: <!UNRESOLVED_REFERENCE!>Exception<!>) { + <!UNRESOLVED_REFERENCE!>System<!>.out<!UNNECESSARY_SAFE_CALL!>?.<!>println(e.getMessage()) + } + + <!UNRESOLVED_REFERENCE!>PrintStream<!>("sdf") + + val c : Com<Int>? = null + + c : <!UNRESOLVED_REFERENCE!>java<!>.lang.Comparable<Int>? + +// Collections.sort<Integer>(ArrayList<Integer>()) + xxx.<!UNRESOLVED_REFERENCE!>Class<!>() +} + + +namespace xxx { + import <!UNRESOLVED_REFERENCE!>java<!>.lang.Class; +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/StringTemplates.jet b/idea/testData/checkerWithErrorTypes/quick/StringTemplates.jet new file mode 100644 index 00000000000..108ffe1d7dd --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/StringTemplates.jet @@ -0,0 +1,21 @@ +fun demo() { + val abc = 1 + val a = "" + val asd = 1 + val bar = 5 + fun map(f : fun () : Any?) : Int = 1 + fun buzz(f : fun () : Any?) : Int = 1 + val sdf = 1 + val foo = 3; + "$abc" + "$" + "$.$.asdf$\t" + "asd\$" + "asd$a<!ILLEGAL_ESCAPE_SEQUENCE!>\x<!>" + "asd$a$asd$ $<!UNRESOLVED_REFERENCE!>xxx<!>" + "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" + "foo${bar + map {foo}}sdfsdf" + "foo${bar + map { "foo" }}sdfsdf" + "foo${bar + map { + "foo$sdf${ buzz{}}" }}sdfsdf" +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/SupertypeListChecks.jet b/idea/testData/checkerWithErrorTypes/quick/SupertypeListChecks.jet new file mode 100644 index 00000000000..78050c67ae8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/SupertypeListChecks.jet @@ -0,0 +1,50 @@ +// KT-286 Check supertype lists + +/* +In a supertype list: + Same type should not be mentioned twice + Same type should not be indirectly mentioned with incoherent type arguments + Every trait's required dependencies should be satisfied + No final types should appear + Only one class is allowed +*/ + +class C1() + +open class OC1() + +open class C2 {} + +open class C3 {} + +trait T1 {} + +trait T2<T> {} + +trait Test<!CONSTRUCTOR_IN_TRAIT!>()<!> { + <!CONSTRUCTOR_IN_TRAIT, SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>(x : Int) {} +} + +trait Test1 : C2<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()<!> {} + +trait Test2 : C2 {} + +trait Test3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {} + +trait Test4 : T1 {} + +trait Test5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {} + +trait Test6 : <!FINAL_SUPERTYPE!>C1<!> {} + +class CTest1() : OC1() {} + +class CTest2 : C2 {} + +class CTest3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {} + +class CTest4 : T1 {} + +class CTest5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {} + +class CTest6 : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>C1<!> {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/TraitSupertypeList.jet b/idea/testData/checkerWithErrorTypes/quick/TraitSupertypeList.jet new file mode 100644 index 00000000000..7f109773457 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/TraitSupertypeList.jet @@ -0,0 +1,11 @@ +open class bar() + +trait Foo<!CONSTRUCTOR_IN_TRAIT!>()<!> : bar<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> { + <!CONSTRUCTOR_IN_TRAIT, SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>(x : Int) {} +} + +trait Foo2 : bar, Foo { +} + +open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {} +open class Foo12 : bar<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>, <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/UnreachableCode.jet b/idea/testData/checkerWithErrorTypes/quick/UnreachableCode.jet new file mode 100644 index 00000000000..c5ecb1191de --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/UnreachableCode.jet @@ -0,0 +1,161 @@ +fun t1() : Int{ + return 0 + <!UNREACHABLE_CODE!>1<!> +} + +fun t1a() : Int { + <!RETURN_TYPE_MISMATCH!>return<!> + <!UNREACHABLE_CODE!>return 1<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t1b() : Int { + return 1 + <!UNREACHABLE_CODE!>return 1<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t1c() : Int { + return 1 + <!RETURN_TYPE_MISMATCH, UNREACHABLE_CODE!>return<!> + <!UNREACHABLE_CODE!>1<!> +} + +fun t2() : Int { + if (1 > 2) + return 1 + else return 1 + <!UNREACHABLE_CODE!>1<!> +} + +fun t2a() : Int { + if (1 > 2) { + return 1 + <!UNREACHABLE_CODE!>1<!> + } else { return 1 + <!UNREACHABLE_CODE!>2<!> + } + <!UNREACHABLE_CODE!>1<!> +} + +fun t3() : Any { + if (1 > 2) + return 2 + else return "" + <!UNREACHABLE_CODE!>1<!> +} + +fun t4(a : Boolean) : Int { + do { + return 1 + } + while (<!UNREACHABLE_CODE!>a<!>) + <!UNREACHABLE_CODE!>1<!> +} + +fun t4break(a : Boolean) : Int { + do { + break + } + while (<!UNREACHABLE_CODE!>a<!>) + return 1 +} + +fun t5() : Int { + do { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + while (<!UNREACHABLE_CODE!>1 > 2<!>) + <!UNREACHABLE_CODE!>return 1<!> +} + +fun t6() : Int { + while (1 > 2) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t6break() : Int { + while (1 > 2) { + break + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7(b : Int) : Int { + for (i in 1..b) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7break(b : Int) : Int { + for (i in 1..b) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + return 1 +} + +fun t7() : Int { + try { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + catch (e : Any) { + 2 + } + return 1 // this is OK, like in Java +} + +fun t8() : Int { + try { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + catch (e : Any) { + return 1 + <!UNREACHABLE_CODE!>2<!> + } + <!UNREACHABLE_CODE!>return 1<!> +} + +fun blockAndAndMismatch() : Boolean { + <!UNREACHABLE_CODE!>(return true) || (return false)<!> + <!UNREACHABLE_CODE!>return true<!> +} + +fun tf() : Int { + try {<!UNREACHABLE_CODE!>return 1<!>} finally{return 1} + <!UNREACHABLE_CODE!>return 1<!> +} + +fun failtest(a : Int) : Int { + <!UNREACHABLE_BECAUSE_OF_NOTHING!>if (fail() || true) { + + }<!> + <!UNREACHABLE_BECAUSE_OF_NOTHING!>return 1<!> +} + +fun foo(a : Nothing) : Unit { + 1 + a + <!UNREACHABLE_BECAUSE_OF_NOTHING!>2<!> +} + +fun fail() : Nothing { + throw <!UNRESOLVED_REFERENCE!>java<!>.lang.RuntimeException() +} + +fun nullIsNotNothing() : Unit { + val x : Int? = 1 + if (x != null) { + return + } + fail() +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Unresolved.jet b/idea/testData/checkerWithErrorTypes/quick/Unresolved.jet new file mode 100644 index 00000000000..8770659c971 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Unresolved.jet @@ -0,0 +1,30 @@ +namespace unresolved + +fun testGenericArgumentsCount() { + val p1: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2) + val p2: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2) +} + +fun testUnresolved() { + if (<!UNRESOLVED_REFERENCE!>a<!> is String) { + val s = <!UNRESOLVED_REFERENCE!>a<!> + } + <!UNRESOLVED_REFERENCE!>foo<!>(<!UNRESOLVED_REFERENCE!>a<!>) + val s = "s" + <!UNRESOLVED_REFERENCE!>foo<!>(s) + foo1(<!UNRESOLVED_REFERENCE!>i<!>) + s.<!UNRESOLVED_REFERENCE!>foo<!>() + + when(<!UNRESOLVED_REFERENCE!>a<!>) { + is Int => <!UNRESOLVED_REFERENCE!>a<!> + is String => <!UNRESOLVED_REFERENCE!>a<!> + } + + //TODO + for (j in <!UNRESOLVED_REFERENCE!>collection<!>) { + val i: Int = j + j += 1 + } +} + +fun foo1(i: Int) {} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/Variance.jet b/idea/testData/checkerWithErrorTypes/quick/Variance.jet new file mode 100644 index 00000000000..5a23caa9275 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/Variance.jet @@ -0,0 +1,40 @@ +namespace variance + +abstract class Consumer<in T> {} + +abstract class Producer<out T> {} + +abstract class Usual<T> {} + +fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) { + val c1: Consumer<Any> = <!TYPE_MISMATCH!>c<!> + val c2: Consumer<Int> = c1 + + val p1: Producer<Any> = p + val p2: Producer<Int> = <!TYPE_MISMATCH!>p1<!> + + val u1: Usual<Any> = <!TYPE_MISMATCH!>u<!> + val u2: Usual<Int> = <!TYPE_MISMATCH!>u1<!> +} + +//Arrays copy example +class Array<T>(val length : Int) { + fun get(index : Int) : T { return null } + fun set(index : Int, value : T) { /* ... */ } +} + +fun copy1(from : Array<Any>, to : Array<Any>) {} + +fun copy2(from : Array<out Any>, to : Array<in Any>) {} + +fun <T> copy3(from : Array<out T>, to : Array<in T>) {} + +fun copy4(from : Array<out Number>, to : Array<in Int>) {} + +fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) { + copy1(<!TYPE_MISMATCH!>ints<!>, any) + copy2(ints, any) //ok + copy2(ints, <!TYPE_MISMATCH!>numbers<!>) + copy3<Int>(ints, numbers) + copy4(ints, numbers) //ok +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/When.jet b/idea/testData/checkerWithErrorTypes/quick/When.jet new file mode 100644 index 00000000000..1a4b8aa96f6 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/When.jet @@ -0,0 +1,61 @@ +fun foo() : Int { + val s = "" + val x = 1 + when (x) { + is * => 1 + is <!INCOMPATIBLE_TYPES!>String<!> => 1 + !is Int => 1 + is Any? => 1 + <!INCOMPATIBLE_TYPES!>s<!> => 1 + 1 => 1 + 1 + <!UNRESOLVED_REFERENCE!>a<!> => 1 + in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 + !in 1..<!UNRESOLVED_REFERENCE!>a<!> => 1 + .<!UNRESOLVED_REFERENCE!>a<!> => 1 + .equals(1).<!UNRESOLVED_REFERENCE!>a<!> => 1 + <!UNNECESSARY_SAFE_CALL!>?.<!>equals(1) => 1 + else => 1 + } + return when (<!USELESS_ELVIS!>x<!>?:null) { + <!UNSAFE_CALL!>.<!>equals(1) => 1 + ?.equals(1).equals(2) => 1 + } +} + +val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() + +fun test() { + val x = 1; + val s = ""; + + when (x) { + <!INCOMPATIBLE_TYPES!>s<!> => 1 + is <!INCOMPATIBLE_TYPES!>""<!> => 1 + x => 1 + is 1 => 1 + is <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, 1)<!> => 1 + } + + val z = (1, 1) + + when (z) { + is (*, *) => 1 + is (*, 1) => 1 + is (1, 1) => 1 + is (1, <!INCOMPATIBLE_TYPES!>"1"<!>) => 1 + is <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, "1", *)<!> => 1 + is boo @ (1, <!INCOMPATIBLE_TYPES!>"a"<!>, *) => 1 + is boo @ <!TYPE_MISMATCH_IN_TUPLE_PATTERN!>(1, *)<!> => 1 + } + + when (z) { + <!ELSE_MISPLACED_IN_WHEN!>else => 1<!> + (1, 1) => 2 + } + + when (z) { + else => 1 + } +} + +val (Int, Int).boo : (Int, Int, Int) = (1, 1, 1) \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/AmbiguityOnLazyTypeComputation.jet b/idea/testData/checkerWithErrorTypes/quick/regression/AmbiguityOnLazyTypeComputation.jet new file mode 100644 index 00000000000..6d519d6b10b --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/AmbiguityOnLazyTypeComputation.jet @@ -0,0 +1,12 @@ +// One of the two passes is making a scope and turning vals into functions +// See KT-76 + +namespace x + +val b : Foo = Foo() +val a1 = b.compareTo(2) + +class Foo() { + fun compareTo(other : Byte) : Int = 0 + fun compareTo(other : Char) : Int = 0 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/AssignmentsUnderOperators.jet b/idea/testData/checkerWithErrorTypes/quick/regression/AssignmentsUnderOperators.jet new file mode 100644 index 00000000000..5a7c24b7fd0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/AssignmentsUnderOperators.jet @@ -0,0 +1,6 @@ +fun test() { + val a : Any? = null + if (a is Any) else a = null; + while (a is Any) a = null + while (true) a = null +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/CoercionToUnit.jet b/idea/testData/checkerWithErrorTypes/quick/regression/CoercionToUnit.jet new file mode 100644 index 00000000000..6733ab3a31e --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/CoercionToUnit.jet @@ -0,0 +1,9 @@ +fun foo(u : Unit) : Int = 1 + +fun test() : Int { + foo(<!TYPE_MISMATCH!>1<!>) + val a : fun() : Unit = { + foo(<!TYPE_MISMATCH!>1<!>) + } + return 1 +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/DoubleDefine.jet b/idea/testData/checkerWithErrorTypes/quick/regression/DoubleDefine.jet new file mode 100644 index 00000000000..eb0616233bd --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/DoubleDefine.jet @@ -0,0 +1,66 @@ +import <!UNRESOLVED_REFERENCE!>java<!>.* +import <!UNRESOLVED_REFERENCE!>util<!>.* + +import <!UNRESOLVED_REFERENCE!>java<!>.io.* + +fun takeFirst(expr: StringBuilder): Char { + val c = expr.charAt(0) + expr.deleteCharAt(0) + return c +} + +fun evaluateArg(expr: AbstractStringBuilder, numbers: ArrayList<Int>): Int { + if (expr.length() == 0) throw Exception("Syntax error: Character expected"); + val c = <!OVERLOAD_RESOLUTION_AMBIGUITY!>takeFirst(expr)<!> + if (c <!COMPARE_TO_TYPE_MISMATCH!>>=<!> '0' && c <!COMPARE_TO_TYPE_MISMATCH!><=<!> '9') { + val n = c - '0' + if (!numbers.contains(n)) throw Exception("You used incorrect number: " + n) + numbers.remove(n) + return n + } + throw Exception("Syntax error: Unrecognized character " + c) +} + +fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int { + val lhs = <!OVERLOAD_RESOLUTION_AMBIGUITY!>evaluateArg(expr, numbers)<!> + if (expr.length() <!COMPARE_TO_TYPE_MISMATCH!>><!> 0) { + + } + return lhs +} + +fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int { + val lhs = <!OVERLOAD_RESOLUTION_AMBIGUITY!>evaluateAdd(expr, numbers)<!> + if (expr.length() <!COMPARE_TO_TYPE_MISMATCH!>><!> 0) { + val c = expr.charAt(0) + expr.deleteCharAt(0) + } + return lhs +} + +fun main(args: Array<String>) { + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("24 game") + val numbers = ArrayList<Int>(4) + val rnd = Random(); + val prompt = StringBuilder() + for(val i in 0..3) { + val n = rnd.nextInt(9) + 1 + numbers.add(n) + if (i > 0) prompt.append(" "); + prompt.append(n) + } + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("Your numbers: " + prompt) + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("Enter your expression:") + val reader = BufferedReader(InputStreamReader(System.`in`)) + val expr = StringBuilder(reader.readLine()) + try { + val result = <!OVERLOAD_RESOLUTION_AMBIGUITY!>evaluate(expr, numbers)<!> + if (result != 24) + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("Sorry, that's " + result) + else + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("You won!"); + } + catch(e: Throwable) { + System.out<!UNNECESSARY_SAFE_CALL!>?.<!>println(e.getMessage()) + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet121.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet121.jet new file mode 100644 index 00000000000..fc29dfe5293 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet121.jet @@ -0,0 +1,14 @@ +namespace jet121 { + fun box() : String { + val answer = apply("OK") { String.() : Int => + get(0) + length + } + + return if (answer == 2) "OK" else "FAIL" + } + + fun apply(arg:String, f : fun String.() : Int) : Int { + return arg.f() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet124.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet124.jet new file mode 100644 index 00000000000..317b1438f41 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet124.jet @@ -0,0 +1,8 @@ +fun foo1() : fun (Int) : Int = { (x: Int) => x } + +fun foo() { + val h : fun (Int) : Int = foo1(); + h(1) + val m : fun (Int) : Int = {(a : Int) => 1}//foo1() + m(1) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet169.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet169.jet new file mode 100644 index 00000000000..43f715647c0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet169.jet @@ -0,0 +1,8 @@ +fun set(key : String, value : String) { + val a : String? = "" + when (a) { + "" => a<!UNSAFE_CALL!>.<!>get(0) + is String, is Any => a.compareTo("") + else => a.toString() + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet17.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet17.jet new file mode 100644 index 00000000000..32cf98cd2fc --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet17.jet @@ -0,0 +1,6 @@ +// JET-17 Do not infer property types by the initializer before the containing scope is ready + +class WithC() { + val a = 1 + val b = $a // error here, but must not be +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet183-1.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet183-1.jet new file mode 100644 index 00000000000..37c72d83ef6 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet183-1.jet @@ -0,0 +1,21 @@ +abstract enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + } + + TALKING { + override fun signal() = ProtocolState.WAITING + } + + abstract fun signal() : ProtocolState +} + + +fun box(): String { + val x: ProtocolState = ProtocolState.WAITING + x = x.signal() + if (x != ProtocolState.TALKING) return "fail 1" + x = x.signal() + if (x != ProtocolState.WAITING) return "fail 2" + return "OK" +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet183.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet183.jet new file mode 100644 index 00000000000..b6d9e309306 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet183.jet @@ -0,0 +1,22 @@ +abstract enum class ProtocolState { + WAITING { + override fun signal() = ProtocolState.TALKING + } + + TALKING { + override fun signal() = ProtocolState.WAITING + } + + abstract fun signal() : ProtocolState +} + +enum class Foo<T> { + <!NO_GENERICS_IN_SUPERTYPE_SPECIFIER!>X<!> + +} + + + +fun box() { + val x: ProtocolState = ProtocolState.WAITING +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet53.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet53.jet new file mode 100644 index 00000000000..34ccb13f7b3 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet53.jet @@ -0,0 +1,4 @@ +import <!UNRESOLVED_REFERENCE!>java<!>.util.Collections +import <!UNRESOLVED_REFERENCE!>java<!>.util.List + +val ab = <!UNRESOLVED_REFERENCE!>Collections<!>.emptyList<Int>() : <!UNRESOLVED_REFERENCE!>List<!><Int>? \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet67.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet67.jet new file mode 100644 index 00000000000..47123bfc16a --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet67.jet @@ -0,0 +1,4 @@ +abstract class XXX { + val a : Int abstract get + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet68.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet68.jet new file mode 100644 index 00000000000..2d9cc4c7b21 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet68.jet @@ -0,0 +1,11 @@ +class Foo() + +fun test() { + val f : Foo? = null + if (f == null) { + + } + if (f != null) { + + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet69.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet69.jet new file mode 100644 index 00000000000..07232903a6a --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet69.jet @@ -0,0 +1,10 @@ +class Command() {} + +fun parse(cmd: String): Command? { return null } + +fun Any.equals(other : Any?) : Boolean = this === other + +fun main(args: Array<String>) { + val command = parse("") + if (command == null) 1 // error on this line, but must be OK +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet72.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet72.jet new file mode 100644 index 00000000000..7f1d4fc9386 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet72.jet @@ -0,0 +1,17 @@ +// JET-72 Type inference doesn't work when iterating over ArrayList + +import <!UNRESOLVED_REFERENCE!>java<!>.util.ArrayList + +abstract class Item(val room: <!UNRESOLVED_REFERENCE!>Object<!>) { + abstract val name : String +} + +val items: <!UNRESOLVED_REFERENCE!>ArrayList<!><Item> = <!UNRESOLVED_REFERENCE!>ArrayList<!><Item> + +fun test(room : <!UNRESOLVED_REFERENCE!>Object<!>) { + for(val item: Item in items) { + if (item.room === room) { + <!UNRESOLVED_REFERENCE!>System<!>.out<!UNNECESSARY_SAFE_CALL!>?.<!>println("You see " + item.name) + } + } +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/Jet81.jet b/idea/testData/checkerWithErrorTypes/quick/regression/Jet81.jet new file mode 100644 index 00000000000..71f79e56394 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/Jet81.jet @@ -0,0 +1,22 @@ +// JET-81 Assertion fails when processing self-referring anonymous objects + +val y = object { + val a = y; +} + +val z = y.a; + +object A { + val x = A +} + +val a = object { + { + b + 1 + } + val x = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>b<!> + val y = 1 +} + +val b = a.x +val c = a.y \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/OverrideResolution.jet b/idea/testData/checkerWithErrorTypes/quick/regression/OverrideResolution.jet new file mode 100644 index 00000000000..b545418dff3 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/OverrideResolution.jet @@ -0,0 +1,16 @@ +fun box() { + val a : C + a.foo() +} + +open class A { + open fun foo() {} +} + +open class B : A { + override fun foo() {} +} + +open class C : B { + override fun foo() {} +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/ScopeForSecondaryConstructors.jet b/idea/testData/checkerWithErrorTypes/quick/regression/ScopeForSecondaryConstructors.jet new file mode 100644 index 00000000000..6c671ffe114 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/ScopeForSecondaryConstructors.jet @@ -0,0 +1,17 @@ +class Foo(var bar : Int, barr : Int, val barrr : Int) { + { + bar = 1 + barr = 1 + barrr = 1 + 1 : Int + this : Foo + } + + this(val bar : Int) : this(1, 1, 1) { + bar = 1 + this.bar + 1 : Int + val a : Int =1 + this : Foo + } + } \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/SpecififcityByReceiver.jet b/idea/testData/checkerWithErrorTypes/quick/regression/SpecififcityByReceiver.jet new file mode 100644 index 00000000000..bbca53527c8 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/SpecififcityByReceiver.jet @@ -0,0 +1,9 @@ +fun Any.equals(other : Any?) : Boolean = true + +fun main(args: Array<String>) { + + val command : Any = 1 + + command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null) + command.equals(null) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/ThisConstructorInGenericClass.jet b/idea/testData/checkerWithErrorTypes/quick/regression/ThisConstructorInGenericClass.jet new file mode 100644 index 00000000000..cb4408bd600 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/ThisConstructorInGenericClass.jet @@ -0,0 +1,3 @@ +class Z() { + this(x : Int) : this() {} +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/WrongTraceInCallResolver.jet b/idea/testData/checkerWithErrorTypes/quick/regression/WrongTraceInCallResolver.jet new file mode 100644 index 00000000000..952ac6c3dbe --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/WrongTraceInCallResolver.jet @@ -0,0 +1,9 @@ +open class Foo {} +open class Bar {} + +fun <T : Bar, T1> foo(x : Int) {} +fun <T1, T : Foo> foo(x : Long) {} + +fun f(): Unit { + foo<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>(1) +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/kt251.jet b/idea/testData/checkerWithErrorTypes/quick/regression/kt251.jet new file mode 100644 index 00000000000..bfbc0784224 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/kt251.jet @@ -0,0 +1,33 @@ +class A() { + var x: Int = 0 + get() = <!TYPE_MISMATCH!>"s"<!> + set(value: <!WRONG_SETTER_PARAMETER_TYPE!>String<!>) { + $x = <!TYPE_MISMATCH!>value<!> + } + val y: Int + get(): <!WRONG_GETTER_RETURN_TYPE!>String<!> = "s" + val z: Int + get() { + return <!TYPE_MISMATCH!>"s"<!> + } + + var a: Any = 1 + set(v: <!WRONG_SETTER_PARAMETER_TYPE!>String<!>) { + $a = v + } + val b: Int + get(): <!WRONG_GETTER_RETURN_TYPE!>Any<!> = "s" + val c: Int + get() { + return 1 + } + val d = 1 + get() { + return $d + } + val e = 1 + get(): <!WRONG_GETTER_RETURN_TYPE!>String<!> { + return <!TYPE_MISMATCH!>$e<!> + } + +} \ No newline at end of file diff --git a/idea/testData/checkerWithErrorTypes/quick/regression/kt303.jet b/idea/testData/checkerWithErrorTypes/quick/regression/kt303.jet new file mode 100644 index 00000000000..ed38edc0bf0 --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/quick/regression/kt303.jet @@ -0,0 +1,11 @@ +// KT-303 Stack overflow on a cyclic class hierarchy + +open class Foo() : <!CYCLIC_INHERITANCE_HIERARCHY!>Bar<!>() { + val a : Int = 1 +} + +open class Bar() : <!CYCLIC_INHERITANCE_HIERARCHY!>Foo<!>() { + +} + +val x : Int = <!TYPE_MISMATCH!>Foo()<!> \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/JetLiteFixture.java b/idea/tests/org/jetbrains/jet/JetLiteFixture.java index d3b1f6b3af3..e0c0051493f 100644 --- a/idea/tests/org/jetbrains/jet/JetLiteFixture.java +++ b/idea/tests/org/jetbrains/jet/JetLiteFixture.java @@ -47,7 +47,7 @@ import java.io.IOException; /** * @author abreslav */ -public class JetLiteFixture extends PlatformLiteFixture { +public abstract class JetLiteFixture extends PlatformLiteFixture { protected String myFileExt; @NonNls protected final String myFullDataPath; @@ -127,7 +127,7 @@ public class JetLiteFixture extends PlatformLiteFixture { return doLoadFile(myFullDataPath, name); } - private static String doLoadFile(String myFullDataPath, String name) throws IOException { + protected static String doLoadFile(String myFullDataPath, String name) throws IOException { String fullName = myFullDataPath + File.separatorChar + name; String text = FileUtil.loadFile(new File(fullName), CharsetToolkit.UTF8).trim(); text = StringUtil.convertLineSeparators(text); diff --git a/idea/tests/org/jetbrains/jet/JetTestCaseBase.java b/idea/tests/org/jetbrains/jet/JetTestCaseBase.java index e13ee48f159..f6ba28dcb72 100644 --- a/idea/tests/org/jetbrains/jet/JetTestCaseBase.java +++ b/idea/tests/org/jetbrains/jet/JetTestCaseBase.java @@ -68,7 +68,11 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase { @NotNull protected String getTestFilePath() { - return dataPath + name + ".jet"; + return dataPath + File.separator + name + ".jet"; + } + + protected String getDataPath() { + return dataPath; } public interface NamedTestFactory { diff --git a/idea/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java b/idea/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java new file mode 100644 index 00000000000..b8866a42e46 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/checkers/FullJetPsiCheckerTest.java @@ -0,0 +1,115 @@ +package org.jetbrains.jet.checkers; + +import com.google.common.collect.Lists; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.CharsetToolkit; +import junit.framework.Test; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestCaseBase; +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.plugin.AnalyzerFacade; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * @author abreslav + */ +public class FullJetPsiCheckerTest extends JetTestCaseBase { + + public FullJetPsiCheckerTest(@NonNls String dataPath, String name) { + super(dataPath, name); + } + + + @Override + public void runTest() throws Exception { + String fileName = name + ".jet"; + String fullPath = getTestDataPath() + getTestFilePath(); + + + String expectedText = loadFile(fullPath); + + List<CheckerTestUtil.DiagnosedRange> diagnosedRanges = Lists.newArrayList(); + String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges); + + configureFromFileText(fileName, clearText); + JetFile jetFile = (JetFile) myFile; + BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(jetFile); + + CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() { + @Override + public void missingDiagnostic(String type, int expectedStart, int expectedEnd) { + String message = "Missing " + type + DiagnosticUtils.atLocation(myFile, new TextRange(expectedStart, expectedEnd)); + System.err.println(message); + } + + @Override + public void unexpectedDiagnostic(String type, int actualStart, int actualEnd) { + String message = "Unexpected " + type + DiagnosticUtils.atLocation(myFile, new TextRange(actualStart, actualEnd)); + System.err.println(message); + } + }); + + String actualText = CheckerTestUtil.addDiagnosticMarkersToText(jetFile, bindingContext).toString(); + + assertEquals(expectedText, actualText); + +// String myFullDataPath = getTestDataPath() + getDataPath(); +// System.out.println("myFullDataPath = " + myFullDataPath); +// convert(new File(myFullDataPath + "/../../checker/"), new File(myFullDataPath)); + } + + private String loadFile(String fullPath) throws IOException { + final File ioFile = new File(fullPath); + String fileText = FileUtil.loadFile(ioFile, CharsetToolkit.UTF8); + return StringUtil.convertLineSeparators(fileText); + } + +// private void convert(File src, File dest) throws IOException { +// File[] files = src.listFiles(); +// for (File file : files) { +// try { +// if (file.isDirectory()) { +// File destDir = new File(dest, file.getName()); +// destDir.mkdir(); +// convert(file, destDir); +// continue; +// } +// if (!file.getName().endsWith(".jet")) continue; +// String text = loadFile(file.getAbsolutePath()); +// Pattern pattern = Pattern.compile("</?(error|warning)>"); +// String clearText = pattern.matcher(text).replaceAll(""); +// +// configureFromFileText(file.getName(), clearText); +// +// BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache((JetFile) myFile); +// String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(myFile, bindingContext).toString(); +// +// File destFile = new File(dest, file.getName()); +// FileWriter fileWriter = new FileWriter(destFile); +// fileWriter.write(expectedText); +// fileWriter.close(); +// } +// catch (RuntimeException e) { +// e.printStackTrace(); +// } +// } +// } + + public static Test suite() { + return JetTestCaseBase.suiteForDirectory(JetTestCaseBase.getTestDataPathBase(), "/checkerWithErrorTypes/full/", true, new JetTestCaseBase.NamedTestFactory() { + @NotNull + @Override + public Test createTest(@NotNull String dataPath, @NotNull String name) { + return new FullJetPsiCheckerTest(dataPath, name); + } + }); + } +} diff --git a/idea/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java b/idea/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java index f9c0f0545c8..b76d37388c0 100644 --- a/idea/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java +++ b/idea/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java @@ -58,8 +58,40 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture { String actualText = CheckerTestUtil.addDiagnosticMarkersToText(jetFile, bindingContext).toString(); assertEquals(expectedText, actualText); + +// convert(new File(myFullDataPath + "/../../checker/"), new File(myFullDataPath)); } +// private void convert(File src, File dest) throws IOException { +// File[] files = src.listFiles(); +// for (File file : files) { +// try { +// if (file.isDirectory()) { +// File destDir = new File(dest, file.getName()); +// destDir.mkdir(); +// convert(file, destDir); +// continue; +// } +// if (!file.getName().endsWith(".jet")) continue; +// String text = doLoadFile(file.getParentFile().getAbsolutePath(), file.getName()); +// Pattern pattern = Pattern.compile("</?(error|warning)>"); +// String clearText = pattern.matcher(text).replaceAll(""); +// createAndCheckPsiFile(name, clearText); +// +// BindingContext bindingContext = AnalyzingUtils.getInstance(ImportingStrategy.NONE).analyzeFileWithCache((JetFile) myFile); +// String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(myFile, bindingContext).toString(); +// +// File destFile = new File(dest, file.getName()); +// FileWriter fileWriter = new FileWriter(destFile); +// fileWriter.write(expectedText); +// fileWriter.close(); +// } +// catch (RuntimeException e) { +// e.printStackTrace(); +// } +// } +// } + public static Test suite() { return JetTestCaseBase.suiteForDirectory(JetTestCaseBase.getTestDataPathBase(), "/checkerWithErrorTypes/quick", true, new JetTestCaseBase.NamedTestFactory() { @NotNull