diff --git a/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt new file mode 100644 index 00000000000..2c14316fda1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt @@ -0,0 +1,17 @@ +// FILE: P.java + +import java.util.ArrayList; +import java.util.List; + +public class P { + public List getList() { + return new ArrayList(); + } +} + +// FILE: Test.kt + +fun foo(c: P): MutableList { + // Error should be here: see KT-8168 Typechecker fails for platform collection type + return c.getList() ?: listOf() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.txt b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.txt new file mode 100644 index 00000000000..da801806970 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.txt @@ -0,0 +1,11 @@ +package + +public fun foo(/*0*/ c: P): kotlin.collections.MutableList + +public open class P { + public constructor P() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun getList(): kotlin.collections.(Mutable)List! + 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/testsWithStdLib/ifElseJavaList.kt b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.kt new file mode 100644 index 00000000000..abfc08fe611 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.kt @@ -0,0 +1,16 @@ +// FILE: Java.java + +import java.util.List; + +class Java { + public static List get(List o) { return o; } +} + +// FILE: test.kt + +import java.util.ArrayList + +fun call(): List { + // No errors should be here + return Java.get(if (true) ArrayList() else listOf(0)) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.txt b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.txt new file mode 100644 index 00000000000..d09d82faadb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.txt @@ -0,0 +1,13 @@ +package + +public fun call(): kotlin.collections.List + +public/*package*/ open class Java { + public/*package*/ constructor Java() + 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 + + // Static members + public open operator fun get(/*0*/ o: kotlin.collections.(Mutable)List!): kotlin.collections.(Mutable)List! +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 46f61d02666..37513a5f364 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -65,12 +65,24 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW doTest(fileName); } + @TestMetadata("elvisOnJavaList.kt") + public void testElvisOnJavaList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt"); + doTest(fileName); + } + @TestMetadata("elvisOnUnitInLet.kt") public void testElvisOnUnitInLet() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/elvisOnUnitInLet.kt"); doTest(fileName); } + @TestMetadata("ifElseJavaList.kt") + public void testIfElseJavaList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/ifElseJavaList.kt"); + doTest(fileName); + } + @TestMetadata("implicitCastToAny.kt") public void testImplicitCastToAny() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt");