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 738a4e28903..79da19cb7d0 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 @@ -13479,6 +13479,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.kt"); } + @Test + @TestMetadata("underscoredTypeArgument.kt") + public void testUnderscoredTypeArgument() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.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 cf2ef27371e..efd6d1db8bd 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 @@ -13479,6 +13479,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.kt"); } + @Test + @TestMetadata("underscoredTypeArgument.kt") + public void testUnderscoredTypeArgument() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.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 b4c25783774..c7cdc344874 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 @@ -13479,6 +13479,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.kt"); } + @Test + @TestMetadata("underscoredTypeArgument.kt") + public void testUnderscoredTypeArgument() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 2dfecd8601d..2a38759d15d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -77,6 +77,8 @@ class PSICallResolver( ) { private val givenCandidatesName = Name.special("") + private val arePartiallySpecifiedTypeArgumentsEnabled = languageVersionSettings.supportsFeature(LanguageFeature.PartiallySpecifiedTypeArguments) + val defaultResolutionKinds = setOf( NewResolutionOldInference.ResolutionKind.Function, NewResolutionOldInference.ResolutionKind.Variable, @@ -689,7 +691,7 @@ class PSICallResolver( val typeReference = projection.typeReference ?: return@map TypeArgumentPlaceholder - if (typeReference.isPlaceholder) { + if (typeReference.isPlaceholder && arePartiallySpecifiedTypeArgumentsEnabled) { val resolvedAnnotations = typeResolver.resolveTypeAnnotations(context.trace, context.scope, typeReference) .apply(ForceResolveUtil::forceResolveAllContents) diff --git a/compiler/testData/codegen/box/underscoredTypeArguments/backTicked.kt b/compiler/testData/codegen/box/underscoredTypeArguments/backTicked.kt index efffc595e0b..becce2917ca 100644 --- a/compiler/testData/codegen/box/underscoredTypeArguments/backTicked.kt +++ b/compiler/testData/codegen/box/underscoredTypeArguments/backTicked.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments // WITH_RUNTIME fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) diff --git a/compiler/testData/codegen/box/underscoredTypeArguments/dependentTypeParameters.kt b/compiler/testData/codegen/box/underscoredTypeArguments/dependentTypeParameters.kt index 35ab82e6309..7f21bf67e39 100644 --- a/compiler/testData/codegen/box/underscoredTypeArguments/dependentTypeParameters.kt +++ b/compiler/testData/codegen/box/underscoredTypeArguments/dependentTypeParameters.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments // WITH_RUNTIME // TARGET_BACKEND: JVM diff --git a/compiler/testData/codegen/box/underscoredTypeArguments/lambdaInputType.kt b/compiler/testData/codegen/box/underscoredTypeArguments/lambdaInputType.kt index 6b52a98a6d9..6be52eb2e90 100644 --- a/compiler/testData/codegen/box/underscoredTypeArguments/lambdaInputType.kt +++ b/compiler/testData/codegen/box/underscoredTypeArguments/lambdaInputType.kt @@ -1,3 +1,5 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments + sealed class MyResult{ data class Success(val value: T): MyResult() data class Failure(val exception: Throwable): MyResult() diff --git a/compiler/testData/codegen/box/underscoredTypeArguments/react.kt b/compiler/testData/codegen/box/underscoredTypeArguments/react.kt index 96fc27aed84..5e7815c088c 100644 --- a/compiler/testData/codegen/box/underscoredTypeArguments/react.kt +++ b/compiler/testData/codegen/box/underscoredTypeArguments/react.kt @@ -1,3 +1,5 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments + interface RProps open class RComponent : Component interface RState diff --git a/compiler/testData/codegen/box/underscoredTypeArguments/simple.kt b/compiler/testData/codegen/box/underscoredTypeArguments/simple.kt index 6e127f60c34..4e66fa58a97 100644 --- a/compiler/testData/codegen/box/underscoredTypeArguments/simple.kt +++ b/compiler/testData/codegen/box/underscoredTypeArguments/simple.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments // WITH_RUNTIME fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt index 600d8a9ccae..da579a28673 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +PartiallySpecifiedTypeArguments // !DIAGNOSTICS: -UNCHECKED_CAST // FIR_IDENTICAL // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt new file mode 100644 index 00000000000..6565d67ee0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.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.txt b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.txt new file mode 100644 index 00000000000..0a699436d3f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.txt @@ -0,0 +1,4 @@ +package + +public fun box(): kotlin.String +public fun foo(/*0*/ x: (K) -> T): kotlin.Pair 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 e34a8f24092..5d34b6a9f80 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 @@ -13485,6 +13485,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/typeParameterInConstructor.kt"); } + @Test + @TestMetadata("underscoredTypeArgument.kt") + public void testUnderscoredTypeArgument() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/underscoredTypeArgument.kt"); + } + @Test @TestMetadata("useFunctionLiteralsToInferType.kt") public void testUseFunctionLiteralsToInferType() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index ace963cbdbd..c524a103880 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -238,6 +238,7 @@ enum class LanguageFeature( ProhibitNonExhaustiveIfInRhsOfElvis(KOTLIN_1_7, kind = BUG_FIX), // KT-44705 ForbidExposingTypesInPrimaryConstructorProperties(KOTLIN_1_7, kind = BUG_FIX), ProhibitAccessToEnumCompanionMembersInEnumConstructorCall(KOTLIN_1_7, kind = BUG_FIX), + PartiallySpecifiedTypeArguments(KOTLIN_1_7), // 1.8