diff --git a/compiler/testData/codegen/boxWithStdlib/regressions/kt3850.kt b/compiler/testData/codegen/boxWithStdlib/regressions/kt3850.kt new file mode 100644 index 00000000000..ca5e250355d --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/regressions/kt3850.kt @@ -0,0 +1,6 @@ +class One { + val a1 = arrayOf( + object { val fy = "text"} + )} + +fun box() = if (One().a1[0].fy == "text") "OK" else "fail" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2057.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.kt new file mode 100644 index 00000000000..9f6cf54e955 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import java.util.ArrayList + +fun foo(a : T, b : Collection, c : Int) { +} + +fun arrayListOf(vararg values: T): ArrayList = throw Exception("$values") + +val bar = foo("", arrayListOf(), ) +val bar2 = foo("", arrayListOf(), ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2057.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.txt new file mode 100644 index 00000000000..451227671c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2057.txt @@ -0,0 +1,6 @@ +package + +internal val bar: kotlin.Unit +internal val bar2: kotlin.Unit +internal fun arrayListOf(/*0*/ vararg values: T /*kotlin.Array*/): java.util.ArrayList +internal fun foo(/*0*/ a: T, /*1*/ b: kotlin.Collection, /*2*/ c: kotlin.Int): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2588.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.kt new file mode 100644 index 00000000000..504f5f7909f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +//T-2588 Allow to specify exact super type (expected) in inference if many + +import java.util.HashSet + +class MyClass() + +interface A +interface D +class B : A, D +class C : A, D + +fun hashSetOf(vararg values: T): HashSet = throw Exception("$values") + +fun foo(b: MyClass, c: MyClass) { + val set1 : Set> = hashSetOf(b, c) //type inference expected type mismatch + val set2 = hashSetOf(b, c) //Set> is inferred +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2588.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.txt new file mode 100644 index 00000000000..8efcc0c878e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2588.txt @@ -0,0 +1,37 @@ +package + +internal fun foo(/*0*/ b: MyClass, /*1*/ c: MyClass): kotlin.Unit +internal fun hashSetOf(/*0*/ vararg values: T /*kotlin.Array*/): java.util.HashSet + +internal interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class B : A, D { + public constructor B() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class C : A, D { + public constructor C() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface D { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class MyClass { + public constructor MyClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2754.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.kt new file mode 100644 index 00000000000..6b5394796c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.kt @@ -0,0 +1,28 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// T is the immutable type +interface Builder { + fun build(): T +} + +// T is the immutable type, U is the builder +interface Copyable> { + fun builder(): U +} + +fun , U : Builder> T.copy(fn: U.() -> Unit): T = throw Exception() + +open class Foo(val x: Int, val y: Int) : Copyable { + override fun builder(): FooBuilder = FooBuilder(x, y) + + open class FooBuilder(var x: Int, var y: Int): Builder { + override fun build(): Foo = Foo(x, y) + } +} + +fun test() { + val foo1 = Foo(x = 1, y = 2) + val foo2 = foo1.copy { y = 3 } // this doesn't work + foo2 checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2754.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.txt new file mode 100644 index 00000000000..507f19c225e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2754.txt @@ -0,0 +1,38 @@ +package + +internal fun test(): kotlin.Unit +internal fun , /*1*/ U : Builder> T.copy(/*0*/ fn: U.() -> kotlin.Unit): T + +internal interface Builder { + internal abstract fun build(): T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface Copyable> { + internal abstract fun builder(): U + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal open class Foo : Copyable { + public constructor Foo(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int) + internal final val x: kotlin.Int + internal final val y: kotlin.Int + internal open override /*1*/ fun builder(): Foo.FooBuilder + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal open class FooBuilder : Builder { + public constructor FooBuilder(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int) + internal final var x: kotlin.Int + internal final var y: kotlin.Int + internal open override /*1*/ fun build(): Foo + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.kt new file mode 100644 index 00000000000..5180621417f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// KT-3496 Type inference bug on y[""] + +class B { + fun x (y: B>) { + val z: S = y[""] // does not work with [], but works with .get() + } + fun get(s : String): S = throw Exception() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.txt new file mode 100644 index 00000000000..c404da8b297 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496.txt @@ -0,0 +1,10 @@ +package + +internal final class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun get(/*0*/ s: kotlin.String): S + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + internal final fun x(/*0*/ y: B>): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.kt new file mode 100644 index 00000000000..19716e3ba80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +import java.util.ArrayList + +class F { + fun x (y: F>, w: ArrayList) { + val z: ArrayList = y["", w] + } +} +fun Any.get(s: String, w: ArrayList): ArrayList = throw Exception() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.txt new file mode 100644 index 00000000000..9439ea910a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.txt @@ -0,0 +1,11 @@ +package + +internal fun kotlin.Any.get(/*0*/ s: kotlin.String, /*1*/ w: java.util.ArrayList): java.util.ArrayList + +internal final class F { + public constructor F() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + internal final fun x(/*0*/ y: F>, /*1*/ w: java.util.ArrayList): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt new file mode 100644 index 00000000000..4cd430d0752 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt @@ -0,0 +1,10 @@ +// KT-3559 Strange inference failure error message + +public inline fun let(subj: T?, body: (T) -> R): R? { + return if (subj != null) body(subj) else null +} + + +fun test(s: String?): String? { + return let(s) {s} // Reports: "Inference failed. Expected jet.String? but found jet.String?" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3559.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.txt new file mode 100644 index 00000000000..dd9e3b06ea9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3559.txt @@ -0,0 +1,4 @@ +package + +kotlin.inline() public fun let(/*0*/ subj: T?, /*1*/ body: (T) -> R): R? +internal fun test(/*0*/ s: kotlin.String?): kotlin.String? diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt new file mode 100644 index 00000000000..031c92f9445 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE +//KT-4420 Type inference with type projections + +class Foo +fun Foo.bar(): T = throw Exception() + +fun main(args: Array) { + val f: Foo = Foo() + f.bar() checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt4420.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.txt new file mode 100644 index 00000000000..7f1125d18ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt4420.txt @@ -0,0 +1,11 @@ +package + +internal fun main(/*0*/ args: kotlin.Array): kotlin.Unit +internal fun Foo.bar(): T + +internal final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.kt new file mode 100644 index 00000000000..d3a519cc2d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.kt @@ -0,0 +1,11 @@ +// !CHECK_TYPE + +fun foo(s : String?, b : Boolean) { + if (s == null) return + + val s1 = if (b) "" else s + s1 checkType { _() } + + val s2 = s + s2 checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.txt b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.txt new file mode 100644 index 00000000000..420da32d346 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.txt @@ -0,0 +1,3 @@ +package + +internal fun foo(/*0*/ s: kotlin.String?, /*1*/ b: kotlin.Boolean): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt new file mode 100644 index 00000000000..03cf7f8b523 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt @@ -0,0 +1,9 @@ +// !CHECK_TYPE + +import java.io.File + +fun test() { + val dir = File("dir") + val files = dir.listFiles()?.toList() ?: listOf() // error + files checkType { _>() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.txt new file mode 100644 index 00000000000..b8def46715c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.txt @@ -0,0 +1,3 @@ +package + +internal fun test(): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt new file mode 100644 index 00000000000..921a68f7936 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt @@ -0,0 +1,10 @@ +// !CHECK_TYPE + +fun bar(f: () -> T) : T = f() + +fun test(map: MutableMap) { + val r = bar { + map[1] = 2 + } + r checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.txt new file mode 100644 index 00000000000..3eab57374a6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.txt @@ -0,0 +1,4 @@ +package + +internal fun bar(/*0*/ f: () -> T): T +internal fun test(/*0*/ map: kotlin.MutableMap): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 23be88f7365..9827f921490 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -6896,6 +6896,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt2057.kt") + public void testKt2057() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2057.kt"); + doTest(fileName); + } + @TestMetadata("kt2179.kt") public void testKt2179() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2179.kt"); @@ -6974,12 +6980,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt2588.kt") + public void testKt2588() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2588.kt"); + doTest(fileName); + } + @TestMetadata("kt2741.kt") public void testKt2741() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt"); doTest(fileName); } + @TestMetadata("kt2754.kt") + public void testKt2754() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2754.kt"); + doTest(fileName); + } + @TestMetadata("kt2838.kt") public void testKt2838() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt2838.kt"); @@ -7058,6 +7076,30 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt3496.kt") + public void testKt3496() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt3496.kt"); + doTest(fileName); + } + + @TestMetadata("kt3496_2.kt") + public void testKt3496_2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt3496_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt3559.kt") + public void testKt3559() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt"); + doTest(fileName); + } + + @TestMetadata("kt4420.kt") + public void testKt4420() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt"); + doTest(fileName); + } + @TestMetadata("kt702.kt") public void testKt702() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt"); @@ -12344,6 +12386,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt1275.kt") + public void testKt1275() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/inference/kt1275.kt"); + doTest(fileName); + } + @TestMetadata("kt1355.kt") public void testKt1355() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/inference/kt1355.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java index dd046cf6fa6..15df05dcafd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestWithStdLibGenerated.java @@ -531,6 +531,18 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.kt"); doTest(fileName); } + + @TestMetadata("kt3458.kt") + public void testKt3458() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt"); + doTest(fileName); + } + + @TestMetadata("kt4975.kt") + public void testKt4975() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/kotlinSignature") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index e228260576b..0bd0f75a57e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -3301,6 +3301,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode doTestWithStdlib(fileName); } + @TestMetadata("kt3850.kt") + public void testKt3850() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/regressions/kt3850.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("kt4142.kt") public void testKt4142() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/regressions/kt4142.kt");