diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.kt new file mode 100644 index 00000000000..314af0fb29b --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE! +// ISSUE: KT-28999 + +fun case_1() { + val x = object { } // type of x is +} + +fun case_2() { + val x = object> { } +} + +fun case_3() { + val x = object where T : Comparable<T> { } // ERROR: Where clause is not allowed for objects +} + +val x = object> { + fun test() = 10 as T // OK +} + +fun case_4() { + val x = object { + fun test() = 10 as T + } + + val y = x.test() // type y is T +} + +inline fun case_5() { + val x = object { + fun test() = 10 as T + } + + val z = x.test() + + if (z is T) { + // z is {T!! & T!!} (smart cast from T) + println(z) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.txt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.txt new file mode 100644 index 00000000000..b67d9a855e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.txt @@ -0,0 +1,8 @@ +package + +public val x: kotlin.Any +public fun case_1(): kotlin.Unit +public fun case_2(): kotlin.Unit +public fun case_3(): kotlin.Unit +public fun case_4(): kotlin.Unit +public inline fun case_5(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 7a72b9457d9..b4b5e5f88e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -3109,6 +3109,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.kt"); } + @TestMetadata("typeParametersInAnnonymousObject.kt") + public void testTypeParametersInAnnonymousObject() throws Exception { + runTest("compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.kt"); + } + @TestMetadata("typeParametersInObject.kt") public void testTypeParametersInObject() throws Exception { runTest("compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 6c2f2459178..406f3af861f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -3104,6 +3104,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.kt"); } + @TestMetadata("typeParametersInAnnonymousObject.kt") + public void testTypeParametersInAnnonymousObject() throws Exception { + runTest("compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.kt"); + } + @TestMetadata("typeParametersInObject.kt") public void testTypeParametersInObject() throws Exception { runTest("compiler/testData/diagnostics/tests/classObjects/typeParametersInObject.kt");