[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:
Dmitrii Gridin
2023-08-23 17:25:56 +02:00
parent 6e4d033f89
commit 2f8a64fff2
21 changed files with 255 additions and 10 deletions
@@ -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)
}
@@ -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");
}
}
}