diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 79da19cb7d0..553edfc73fc 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -13485,6 +13485,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); } + @Test + @TestMetadata("underscoredTypeInForbiddenPositions.kt") + public void testUnderscoredTypeInForbiddenPositions() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index efd6d1db8bd..44a01e3b365 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -13485,6 +13485,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); } + @Test + @TestMetadata("underscoredTypeInForbiddenPositions.kt") + public void testUnderscoredTypeInForbiddenPositions() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index c7cdc344874..91f2b36ba0b 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -13485,6 +13485,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); } + @Test + @TestMetadata("underscoredTypeInForbiddenPositions.kt") + public void testUnderscoredTypeInForbiddenPositions() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt index 30fafe48184..d9ad2eda77c 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt @@ -23,9 +23,7 @@ fun box(): String { val z2: Pair = foo<@Anno3("") /**/ _, @[/**/ Anno /**/ Anno3("") /**/] _,> { it.toFloat() } val z31: Pair<@Anno3("") _, Float> = 1 to 1f - val z32: Pair<_, Float> = 1 to 1f val z33: Pair<@Anno3("") (_), Float> = 1 to 1f - val z34: Pair<((_)), Float> = 1 to 1f val z35: Pair<(@Anno3("") (_)), Float> = 1 to 1f return "OK" diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt index e487bb4ed5b..c4874d2d0cf 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt @@ -23,9 +23,7 @@ fun box(): String { val z2: Pair = foo<@Anno3("") /**/ _, @[/**/ Anno /**/ Anno3("") /**/] _,> { it.toFloat() } val z31: Pair<@Anno3("") _, Float> = 1 to 1f - val z32: Pair<_, Float> = 1 to 1f val z33: Pair<@Anno3("") (_), Float> = 1 to 1f - val z34: Pair<((_)), Float> = 1 to 1f val z35: Pair<(@Anno3("") (_)), Float> = 1 to 1f return "OK" diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.fir.kt b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.fir.kt new file mode 100644 index 00000000000..1d5726360a2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.fir.kt @@ -0,0 +1,65 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments +// !DIAGNOSTICS: -UNCHECKED_CAST +// WITH_RUNTIME + +fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) + +class Foo + +class Bar0_<_>> +class Bar1_>> +class Bar2_> +class Bar3 where K : _ +class Bar4<_> + +typealias A1<_> = _ +typealias A2 = Foo<_> +typealias A3 = (_) -> T +typealias A4 = (T) -> () -> _ +typealias A5 = (T) -> (((_))) -> T + +fun foo1(x: _) {} +fun foo2(x: Foo<_>) {} +fun foo3(): _ {} +fun foo5(): Foo<_> {} +fun _> foo6(): Foo<_> {} +fun _> foo7(): Foo<_> {} + +class AA1 : _ +class AA2 : Foo<_> + +fun <`_`> bar(): Foo<_> = TODO() + +fun test() { + val x1 = foo_) -> Unit> { { it } } + val x2 = foo _> { { it } } + val x3 = foo(_)) -> _> { { it } } + val x4 = foo<Int, _ -> Float> { { it } } + val x5 = foo_) -> Float>> { { it } } + val x6 = foo_) -> _>> { { it } } + val x7 = foo _>> { { it } } + + val z32: Pair<_, Float> = 1 to 1f + val z34: Pair<((_)), Float> = 1 to 1f + + val x8: (Float) -> Int = { x: _ -> 10 } + val x9: (Foo) -> Int = { x: Foo<_> -> 10 } + + val x10 = object : _ {} + val x11 = object : Foo<_> {} + + if (x11 is _) { } + if (x11 is Foo<_>) { } + + x10 as _ + x10 as Foo<_> + + val x12: Foo<@_ Int>? = null + val x13: Foo<@_() Int>? = null + val x14: Foo<@Anno(_) Int>? = null + + val x15: _<_>? = null +} + +@Target(AnnotationTarget.TYPE) +annotation class Anno(val x: Int) diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt new file mode 100644 index 00000000000..81f3c920e61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt @@ -0,0 +1,65 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments +// !DIAGNOSTICS: -UNCHECKED_CAST +// WITH_RUNTIME + +fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) + +class Foo + +class Bar0_<_>> +class Bar1_>> +class Bar2_> +class Bar3 where K : _ +class Bar4<_> + +typealias A1<_> = _ +typealias A2 = Foo<_> +typealias A3 = (_) -> T +typealias A4 = (T) -> () -> _ +typealias A5 = (T) -> (((_))) -> T + +fun foo1(x: _) {} +fun foo2(x: Foo<_>) {} +fun foo3(): _ {} +fun foo5(): Foo<_> {} +fun _> foo6(): Foo<_> {} +fun _, _> foo7(): Foo<_> {} + +class AA1 : _ +class AA2 : Foo<_> + +fun <`_`> bar(): Foo<_> = TODO() + +fun test() { + val x1 = foo Unit> { { it } } + val x2 = foo _> { { it } } + val x3 = foo _> { { it } } + val x4 = foo<Int, _ -> Float> { { it } } + val x5 = foo_) -> Float>> { { it } } + val x6 = foo_) -> _>> { { it } } + val x7 = foo _>> { { it } } + + val z32: Pair<_, Float> = 1 to 1f + val z34: Pair<((_)), Float> = 1 to 1f + + val x8: (Float) -> Int = { x: _ -> 10 } + val x9: (Foo) -> Int = { x: Foo<_> -> 10 } + + val x10 = object : _ {} + val x11 = object : Foo<_> {} + + if (x11 is _) { } + if (x11 is Foo<_>) { } + + x10 as _ + x10 as Foo<_> + + val x12: Foo<@_ Int>? = null + val x13: Foo<@_() Int>? = null + val x14: Foo<@Anno(_) Int>? = null + + val x15: _<_>? = null +} + +@Target(AnnotationTarget.TYPE) +annotation class Anno(val x: Int) diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.txt b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.txt new file mode 100644 index 00000000000..20fe034b2a6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.txt @@ -0,0 +1,80 @@ +package + +public fun bar(): Foo<_> +public fun foo(/*0*/ x: (K) -> T): kotlin.Pair +public fun foo1(/*0*/ x: [ERROR : _]): kotlin.Unit +public fun foo2(/*0*/ x: Foo<[ERROR : _]>): kotlin.Unit +public fun foo3(): [ERROR : _] +public fun foo5(): Foo<[ERROR : _]> +public fun foo6(): Foo<_> +public fun foo7(): Foo<_> +public fun test(): kotlin.Unit + +public final class AA1 { + public constructor AA1() + 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 +} + +public final class AA2 : Foo<[ERROR : _]> { + public constructor AA2() + 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 +} + +@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno : kotlin.Annotation { + public constructor Anno(/*0*/ x: kotlin.Int) + public final val x: kotlin.Int + 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 +} + +public final class Bar0 { + public constructor Bar0() + 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 +} + +public final class Bar1> { + public constructor Bar1>() + 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 +} + +public final class Bar2 { + public constructor Bar2() + 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 +} + +public final class Bar3 { + public constructor Bar3() + 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 +} + +public final class Bar4 { + public constructor Bar4() + 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 +} + +public 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 +} +public typealias A1 = _ +public typealias A2 = Foo<[ERROR : _]> +public typealias A3 = ([ERROR : _]) -> T +public typealias A4 = (T) -> () -> [ERROR : _] +public typealias A5 = (T) -> ([ERROR : _]) -> T diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 5d34b6a9f80..cc9851ce4b5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -13491,6 +13491,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); } + @Test + @TestMetadata("underscoredTypeInForbiddenPositions.kt") + public void testUnderscoredTypeInForbiddenPositions() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeInForbiddenPositions.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception {