[Analysis API] Fix exceptions around type parameters being treated as callables
- `toResolvedCallableSymbol`: cast defensively because the resolved symbol might not be a callable symbol. - `toKtCallInfo`: Check that the resolved symbol is actually callable. ^KTIJ-23003 fixed
This commit is contained in:
committed by
teamcity
parent
170c19d293
commit
c5e5140c08
+6
@@ -898,6 +898,12 @@ public class Fe10IdeNormalAnalysisSourceModuleResolveCallTestGenerated extends A
|
|||||||
public void testGetterAssignment() throws Exception {
|
public void testGetterAssignment() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeParameterAsValue.kt")
|
||||||
|
public void testTypeParameterAsValue() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/typeParameterAsValue.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+14
-4
@@ -168,10 +168,20 @@ internal class KtFirCallResolver(
|
|||||||
return when (this) {
|
return when (this) {
|
||||||
is FirResolvable -> {
|
is FirResolvable -> {
|
||||||
when (val calleeReference = calleeReference) {
|
when (val calleeReference = calleeReference) {
|
||||||
is FirResolvedNamedReference -> {
|
is FirResolvedNamedReference -> when (calleeReference.resolvedSymbol) {
|
||||||
val call = createKtCall(psi, this, null, resolveFragmentOfCall)
|
// `calleeReference.resolvedSymbol` isn't guaranteed to be callable. For example, function type parameters used in
|
||||||
?: errorWithFirSpecificEntries("expect `createKtCall` to succeed for resolvable case", fir = this, psi = psi)
|
// expression positions (e.g. `T` in `println(T)`) are parsed as `KtSimpleNameExpression` and built into
|
||||||
KtSuccessCallInfo(call)
|
// `FirPropertyAccessExpression` (which is `FirResolvable`).
|
||||||
|
is FirCallableSymbol<*> -> {
|
||||||
|
val call = createKtCall(psi, this, null, resolveFragmentOfCall)
|
||||||
|
?: errorWithFirSpecificEntries(
|
||||||
|
"expect `createKtCall` to succeed for resolvable case with callable symbol",
|
||||||
|
fir = this,
|
||||||
|
psi = psi
|
||||||
|
)
|
||||||
|
KtSuccessCallInfo(call)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
is FirErrorNamedReference -> {
|
is FirErrorNamedReference -> {
|
||||||
val diagnostic = calleeReference.diagnostic
|
val diagnostic = calleeReference.diagnostic
|
||||||
|
|||||||
+6
@@ -898,6 +898,12 @@ public class FirIdeNormalAnalysisSourceModuleResolveCallTestGenerated extends Ab
|
|||||||
public void testGetterAssignment() throws Exception {
|
public void testGetterAssignment() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeParameterAsValue.kt")
|
||||||
|
public void testTypeParameterAsValue() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/typeParameterAsValue.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+6
@@ -127,6 +127,12 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiImportOptimizerTestGener
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedTypeHiddenByTypeParameter_invalidAsArgument.kt")
|
||||||
|
public void testUnusedTypeHiddenByTypeParameter_invalidAsArgument() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors/unusedTypeHiddenByTypeParameter_invalidAsArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("usedConstructor_invalidArguments.kt")
|
@TestMetadata("usedConstructor_invalidArguments.kt")
|
||||||
public void testUsedConstructor_invalidArguments() throws Exception {
|
public void testUsedConstructor_invalidArguments() throws Exception {
|
||||||
|
|||||||
+6
@@ -898,6 +898,12 @@ public class FirStandaloneNormalAnalysisSourceModuleResolveCallTestGenerated ext
|
|||||||
public void testGetterAssignment() throws Exception {
|
public void testGetterAssignment() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/getterAssignment.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeParameterAsValue.kt")
|
||||||
|
public void testTypeParameterAsValue() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/invalidCode/typeParameterAsValue.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+6
@@ -127,6 +127,12 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiImportOptimizerTe
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unusedTypeHiddenByTypeParameter_invalidAsArgument.kt")
|
||||||
|
public void testUnusedTypeHiddenByTypeParameter_invalidAsArgument() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/importOptimizer/analyseImports/referencesWithErrors/unusedTypeHiddenByTypeParameter_invalidAsArgument.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("usedConstructor_invalidArguments.kt")
|
@TestMetadata("usedConstructor_invalidArguments.kt")
|
||||||
public void testUsedConstructor_invalidArguments() throws Exception {
|
public void testUsedConstructor_invalidArguments() throws Exception {
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// See: KTIJ-23003 (KotlinExceptionWithAttachments)
|
||||||
|
|
||||||
|
fun <T> test(x: Any) {
|
||||||
|
println(<expr>T</expr>)
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
dependency.T
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
// See: KTIJ-23003 (ClassCastException)
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
import dependency.T
|
||||||
|
|
||||||
|
fun <T> usage() {
|
||||||
|
println(T)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: dependency.kt
|
||||||
|
package dependency
|
||||||
|
|
||||||
|
class T(i: Int)
|
||||||
@@ -74,7 +74,7 @@ fun FirExpression.toReference(): FirReference? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun FirExpression.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
fun FirExpression.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
||||||
return toResolvedCallableReference()?.resolvedSymbol as FirCallableSymbol<*>?
|
return toResolvedCallableReference()?.resolvedSymbol as? FirCallableSymbol<*>?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirReference.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
fun FirReference.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
||||||
|
|||||||
Reference in New Issue
Block a user