[FIR] KT-54980 Fix resolvability of too few/too many type arguments

- If too few or too many type arguments were provided, they were all
  thrown away in `TypeArgumentMapping`,
  `FirCallCompletionResultsWriterTransformer`, and `KtFirCallResolver`.
  The fix handles type arguments of the wrong arity more gracefully.
  - Note for `TypeArgumentMapping`: Excess type arguments are not needed
    for candidate resolution. Excess type arguments are still resolved
    due to the handling in `FirCallCompletionResultsWriterTransformer`.
- Post-processing in `AllCandidatesResolver`: When all candidates are
  resolved in `AllCandidatesResolver.getAllCandidates`, the function
  builds a FIR file. During that resolution, the
  `generic<String, String>` call (in example
  `functionCallWithTooFewTypeArguments.kt`) is correctly marked as
  inapplicable, but the missing type argument is inferred as an error
  type. `firFile` then contains a function call
  `generic<String, String, ERROR>` instead of `generic<String, String>`.
  This call is still marked as inapplicable. Despite that, the
  *subsequent* resolution by
  `bodyResolveComponents.callResolve.collectAllCandidates` disregards
  the call's inapplicability and resolves successfully into an
  applicable candidate. This is because `CandidateFactory` doesn't make
  any guarantees for already inapplicable calls. The fix adds
  post-processing to `AllCandidatesResolver` to preserve candidate
  inapplicability.
- Most tests that this commit changes had slightly different results due
  to type arguments becoming resolvable.
- `wrongNumberOfTypeArguments.kt` and
  `wrongNumberOfArgumentsInTypeAliasConstructor.kt`:
  `ConeDiagnostic.toFirDiagnostics` prefers specific errors. Because
  `ARGUMENT_TYPE_MISMATCH` is specific and `INAPPLICABLE_CANDIDATE` is
  not, only the former is reported. I see no reason to pass an illegally
  typed argument in either test, so the change reduces the errors to
  `INAPPLICABLE_CANDIDATE`.
- `typeAliasSamAdapterConstructors2.fir.kt`: See KT-55007.
- Disable `mismatchTypeParameters` JS backend test due to its handling
  of excess type arguments. See KT-55250.

^KT-54980 fixed
This commit is contained in:
Marco Pennekamp
2022-11-21 19:15:50 +01:00
committed by teamcity
parent d6a9235d05
commit 5f554d0065
56 changed files with 721 additions and 37 deletions
@@ -297,6 +297,30 @@ public class Fe10IdeNormalAnalysisSourceModuleResolveCandidatesTestGenerated ext
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithSpreadArgument.kt");
}
@Test
@TestMetadata("functionCallWithTooFewTypeArguments.kt")
public void testFunctionCallWithTooFewTypeArguments() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithTooFewTypeArguments.kt");
}
@Test
@TestMetadata("functionCallWithTooFewTypeArguments2.kt")
public void testFunctionCallWithTooFewTypeArguments2() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithTooFewTypeArguments2.kt");
}
@Test
@TestMetadata("functionCallWithTooManyTypeArguments.kt")
public void testFunctionCallWithTooManyTypeArguments() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithTooManyTypeArguments.kt");
}
@Test
@TestMetadata("functionCallWithTooManyTypeArguments2.kt")
public void testFunctionCallWithTooManyTypeArguments2() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCandidates/singleCandidate/functionCallWithTooManyTypeArguments2.kt");
}
@Test
@TestMetadata("functionCallWithTypeArgument.kt")
public void testFunctionCallWithTypeArgument() throws Exception {
@@ -622,6 +622,48 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
runTest("analysis/analysis-api/testData/referenceResolve/TypeArgumentBeforeDot.kt");
}
@Test
@TestMetadata("typeArgument_tooFewTypeArguments1.kt")
public void testTypeArgument_tooFewTypeArguments1() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooFewTypeArguments1.kt");
}
@Test
@TestMetadata("typeArgument_tooFewTypeArguments1a.kt")
public void testTypeArgument_tooFewTypeArguments1a() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooFewTypeArguments1a.kt");
}
@Test
@TestMetadata("typeArgument_tooFewTypeArguments2.kt")
public void testTypeArgument_tooFewTypeArguments2() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooFewTypeArguments2.kt");
}
@Test
@TestMetadata("typeArgument_tooManyTypeArguments1.kt")
public void testTypeArgument_tooManyTypeArguments1() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooManyTypeArguments1.kt");
}
@Test
@TestMetadata("typeArgument_tooManyTypeArguments1a.kt")
public void testTypeArgument_tooManyTypeArguments1a() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooManyTypeArguments1a.kt");
}
@Test
@TestMetadata("typeArgument_tooManyTypeArguments2.kt")
public void testTypeArgument_tooManyTypeArguments2() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooManyTypeArguments2.kt");
}
@Test
@TestMetadata("typeArgument_tooManyTypeArguments2a.kt")
public void testTypeArgument_tooManyTypeArguments2a() throws Exception {
runTest("analysis/analysis-api/testData/referenceResolve/typeArgument_tooManyTypeArguments2a.kt");
}
@Test
@TestMetadata("ValueParameter.kt")
public void testValueParameter() throws Exception {