[AA FIR] fix exception from vararg parameter with invalid type
It is true that for vararg parameter `arrayElementType` always have to be not null, but it required resolution to TYPES phase. But in case of the error type, the type reference is treated as resolved, so we are not obligatory to resolve such reference to TYPES, because we already have the resolved type. So we can make the rule of KtFirValueParameterSymbol#returnType less strict, and varargElementType will effectively do the same as lazy resolve + arrayElementType ^KT-61422 Fixed
This commit is contained in:
+12
@@ -364,5 +364,17 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends A
|
||||
public void testParameterNotFunctionalType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/parameterNotFunctionalType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargWithoutType.kt")
|
||||
public void testVarargWithoutType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/varargWithoutType.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-10
@@ -24,10 +24,8 @@ import org.jetbrains.kotlin.fir.correspondingProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.renderWithType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.fir.types.varargElementType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
internal class KtFirValueParameterSymbol(
|
||||
override val firSymbol: FirValueParameterSymbol,
|
||||
@@ -50,13 +48,8 @@ internal class KtFirValueParameterSymbol(
|
||||
|
||||
override val returnType by cached {
|
||||
val returnType = firSymbol.resolvedReturnType
|
||||
return@cached if (firSymbol.isVararg) {
|
||||
// There SHOULD always be an array element type (even if it is an error type, e.g., unresolved).
|
||||
val arrayElementType = returnType.arrayElementType()
|
||||
?: errorWithAttachment("No array element type for vararg value parameter") {
|
||||
withFirEntry("fir", firSymbol.fir)
|
||||
}
|
||||
builder.typeBuilder.buildKtType(arrayElementType)
|
||||
if (firSymbol.isVararg) {
|
||||
builder.typeBuilder.buildKtType(returnType.varargElementType())
|
||||
} else {
|
||||
builder.typeBuilder.buildKtType(returnType)
|
||||
}
|
||||
|
||||
+12
@@ -364,5 +364,17 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends Ab
|
||||
public void testParameterNotFunctionalType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/parameterNotFunctionalType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargWithoutType.kt")
|
||||
public void testVarargWithoutType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/varargWithoutType.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -364,5 +364,17 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByPsiTestGenerated ext
|
||||
public void testParameterNotFunctionalType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/parameterNotFunctionalType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/vararg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargWithoutType.kt")
|
||||
public void testVarargWithoutType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/varargWithoutType.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
fun foo(vararg ints: Int) {
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo(vararg ints: kotlin.Int)
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /foo
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isActual: false
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: foo
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Unit
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: true
|
||||
name: ints
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
]
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo(vararg ints: ERROR(No type specified for unknown element))
|
||||
analysis/analysis-api/testData/symbols/symbolByPsi/valueParameters/varargWithoutType.descriptors.txt
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /foo
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isActual: false
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: foo
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Unit
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: true
|
||||
name: ints
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtTypeErrorType:
|
||||
annotationsList: []
|
||||
type: ERROR_TYPE
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
]
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
fun foo(vararg ints:) {
|
||||
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun foo(vararg ints: ERROR(Incomplete code))
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /foo
|
||||
contextReceivers: []
|
||||
contractEffects: []
|
||||
hasStableParameterNames: true
|
||||
isActual: false
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExpect: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: foo
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtUsualClassType:
|
||||
annotationsList: []
|
||||
ownTypeArguments: []
|
||||
type: kotlin/Unit
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: true
|
||||
name: ints
|
||||
origin: SOURCE
|
||||
receiverParameter: null
|
||||
returnType: KtTypeErrorType:
|
||||
annotationsList: []
|
||||
type: ERROR CLASS: Incomplete code
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
]
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesByPsiForLibraryTestGenerated extends AbstractSymb
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesEqualityByPsiForLibraryTestGenerated extends Abst
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesParentingByPsiForLibraryTestGenerated extends Abs
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesByPsiForSourceTestGenerated extends AbstractSymbo
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesEqualityByPsiForSourceTestGenerated extends Abstr
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+6
@@ -453,6 +453,12 @@ public class SymbolLightClassesParentingByPsiForSourceTestGenerated extends Abst
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/valueClassInSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("varargParameterWithoutType.kt")
|
||||
public void testVarargParameterWithoutType() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/facades/varargParameterWithoutType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wildcardOptimization.kt")
|
||||
public void testWildcardOptimization() throws Exception {
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public final class VarargParameterWithoutTypeKt /* VarargParameterWithoutTypeKt*/ {
|
||||
public static final /* vararg */ void someFun(error.NonExistentClass...);// someFun(error.NonExistentClass[])
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
public final class VarargParameterWithoutTypeKt /* VarargParameterWithoutTypeKt*/ {
|
||||
public static final /* vararg */ void someFun(@org.jetbrains.annotations.NotNull() error.NonExistentClass...);// someFun(error.NonExistentClass[])
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun someFun(vararg values: )
|
||||
|
||||
// COMPILATION_ERRORS
|
||||
Reference in New Issue
Block a user