From 372879b8e720f60fce11d835857accb33b21b1dc Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 8 Jun 2022 18:07:20 +0200 Subject: [PATCH] [FE 1.0] Don't fail with exception on unresolved type with type argument ^KT-50223 Fixed --- ...DiagnosisCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ .../FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...dFrontendDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../calls/components/CompletionModeCalculator.kt | 5 +++-- .../unresolvedTypeWithTypeArguments.fir.kt | 7 +++++++ .../incompleteCode/unresolvedTypeWithTypeArguments.kt | 7 +++++++ .../incompleteCode/unresolvedTypeWithTypeArguments.txt | 10 ++++++++++ .../kotlin/test/runners/DiagnosticTestGenerated.java | 6 ++++++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.fir.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.txt 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 a3fd8c29821..da542a71e6c 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 @@ -13356,6 +13356,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.kt"); } + @Test + @TestMetadata("unresolvedTypeWithTypeArguments.kt") + public void testUnresolvedTypeWithTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt"); + } + @Test @TestMetadata("variableDeclarationInSelector.kt") public void testVariableDeclarationInSelector() 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 b9574b07e66..765746b283d 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 @@ -13356,6 +13356,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.kt"); } + @Test + @TestMetadata("unresolvedTypeWithTypeArguments.kt") + public void testUnresolvedTypeWithTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt"); + } + @Test @TestMetadata("variableDeclarationInSelector.kt") public void testVariableDeclarationInSelector() 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 6f688e991b3..147a10423ee 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 @@ -13356,6 +13356,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.kt"); } + @Test + @TestMetadata("unresolvedTypeWithTypeArguments.kt") + public void testUnresolvedTypeWithTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt"); + } + @Test @TestMetadata("variableDeclarationInSelector.kt") public void testVariableDeclarationInSelector() throws Exception { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt index 3a6d0bd58aa..d5fd8e80d90 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt @@ -136,10 +136,11 @@ class CompletionModeCalculator { fixationDirectionsCollector: MutableSet ) { val typeArgumentsCount = type.argumentsCount() - if (typeArgumentsCount > 0) { + val typeConstructor = type.typeConstructor() + if (typeArgumentsCount > 0 && typeArgumentsCount == typeConstructor.parametersCount()) { for (position in 0 until typeArgumentsCount) { val argument = type.getArgument(position) - val parameter = type.typeConstructor().getParameter(position) + val parameter = typeConstructor.getParameter(position) if (argument.isStarProjection()) continue diff --git a/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.fir.kt new file mode 100644 index 00000000000..6bd14a5d485 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.fir.kt @@ -0,0 +1,7 @@ +abstract class MyClass { + abstract fun foo(): (P1) -> Unknown + + private fun callTryConvertConstant() { + println(foo()) + } +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt new file mode 100644 index 00000000000..7f547b4812f --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt @@ -0,0 +1,7 @@ +abstract class MyClass { + abstract fun foo(): (P1) -> Unknown + + private fun callTryConvertConstant() { + println(foo()) + } +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.txt b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.txt new file mode 100644 index 00000000000..800688d0858 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.txt @@ -0,0 +1,10 @@ +package + +public abstract class MyClass { + public constructor MyClass() + private final fun callTryConvertConstant(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): (P1) -> [Error type: Unresolved type for Unknown] + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 516d8fd469d..e4891a6f4c3 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 @@ -13362,6 +13362,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedOperation.kt"); } + @Test + @TestMetadata("unresolvedTypeWithTypeArguments.kt") + public void testUnresolvedTypeWithTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/incompleteCode/unresolvedTypeWithTypeArguments.kt"); + } + @Test @TestMetadata("variableDeclarationInSelector.kt") public void testVariableDeclarationInSelector() throws Exception {