diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index b6a52be1eea..7aa553ab10a 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1782,8 +1782,9 @@ open class RawFirBuilder( source = projectionSource } } + val argumentList = typeProjection.parent as? KtTypeArgumentList val typeReference = typeProjection.typeReference - if (typeReference?.isPlaceholder == true) { + if (argumentList?.parent is KtCallExpression && typeReference?.isPlaceholder == true) { return buildPlaceholderProjection { source = projectionSource } diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt new file mode 100644 index 00000000000..30fafe48184 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.fir.kt @@ -0,0 +1,32 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments +// !DIAGNOSTICS: -UNCHECKED_CAST +// WITH_RUNTIME + +fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) + +@Repeatable +@Target(AnnotationTarget.TYPE) +annotation class Anno + +@Repeatable +@Target(AnnotationTarget.TYPE) +annotation class Anno2 + +@Repeatable +@Target(AnnotationTarget.TYPE) +annotation class Anno3(val x: String) + +fun box(): String { + val x = foo<@Anno Int, @Anno _> { it.toFloat() } + val y: Pair = foo<@[Anno Anno2] _, @Anno _> { it.toFloat() } + val z1: Pair = foo<@Anno @Anno2 /**/ _, @[/**/ Anno /**/ ] _> { it.toFloat() } + 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 da579a28673..e487bb4ed5b 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt @@ -1,6 +1,5 @@ // !LANGUAGE: +PartiallySpecifiedTypeArguments // !DIAGNOSTICS: -UNCHECKED_CAST -// FIR_IDENTICAL // WITH_RUNTIME fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) @@ -23,6 +22,11 @@ fun box(): String { val z1: Pair = foo<@Anno @Anno2 /**/ _, @[/**/ Anno /**/ ] _> { it.toFloat() } val z2: Pair = foo<@Anno3("") /**/ _, @[/**/ Anno /**/ Anno3("") /**/] _,> { it.toFloat() } - val z3: Pair<@Anno3("") _, Float> = 1 to 1f + 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/illegalUnderscoredTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt index 5a41685b0ab..08f298a2f43 100644 --- a/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt @@ -5,6 +5,6 @@ fun foo(x: (K) -> T): Pair = TODO() class Foo fun main() { - val x = foo> { it.toFloat() } + val x = foo_>> { it.toFloat() } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.fir.kt new file mode 100644 index 00000000000..cf7e90aab08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.fir.kt @@ -0,0 +1,10 @@ +// FIR_IDENTICAL +// !DIAGNOSTICS: -UNCHECKED_CAST +// WITH_RUNTIME + +fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) + +fun box(): String { + val x = foo { it.toFloat() } // Pair + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt index 6565d67ee0c..0d9879e1d42 100644 --- a/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNCHECKED_CAST // WITH_RUNTIME