[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:
committed by
teamcity
parent
d6a9235d05
commit
5f554d0065
+6
@@ -0,0 +1,6 @@
|
||||
// COMPILATION_ERRORS
|
||||
fun <A, B, C> generic() { }
|
||||
|
||||
fun foo() {
|
||||
generic<<caret>String, String>()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in kotlin) class String : kotlin.Comparable<kotlin.String>, kotlin.CharSequence, java.io.Serializable
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// COMPILATION_ERRORS
|
||||
interface X
|
||||
|
||||
fun <A, B, C> generic() { }
|
||||
|
||||
fun foo() {
|
||||
generic<String, <caret>X>()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in ROOT) interface X
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// COMPILATION_ERRORS
|
||||
fun <A, B, C> generic(a: A, b: B, c: C) { }
|
||||
|
||||
fun foo() {
|
||||
generic<<caret>String, String>("a", "b", "c")
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in kotlin) class String : kotlin.Comparable<kotlin.String>, kotlin.CharSequence, java.io.Serializable
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// COMPILATION_ERRORS
|
||||
interface X
|
||||
interface Y
|
||||
|
||||
fun <A> generic() { }
|
||||
|
||||
fun foo() {
|
||||
generic<X, <caret>Y>()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in ROOT) interface Y
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// COMPILATION_ERRORS
|
||||
interface X
|
||||
interface Y
|
||||
|
||||
fun <A> generic() { }
|
||||
|
||||
fun foo() {
|
||||
generic<<caret>X, Y>()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in ROOT) interface X
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// COMPILATION_ERRORS
|
||||
interface X
|
||||
|
||||
fun <A> generic(a: A) { }
|
||||
|
||||
fun foo() {
|
||||
generic<Int, <caret>X>(5)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in ROOT) interface X
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// COMPILATION_ERRORS
|
||||
interface X
|
||||
|
||||
fun <A> generic(a: A) { }
|
||||
|
||||
fun foo() {
|
||||
generic<<caret>Int, X>(5)
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in kotlin) class Intprivate constructor : kotlin.Number(), kotlin.Comparable<kotlin.Int>, java.io.Serializable
|
||||
Reference in New Issue
Block a user