[HL API] Fix FE10 implementation of KtExpressionTypeProvider
This commit is contained in:
+7
-2
@@ -72,8 +72,13 @@ class KtFe10ExpressionTypeProvider(
|
|||||||
|
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
val bindingContext = analysisContext.analyze(typeReference, AnalysisMode.PARTIAL)
|
val bindingContext = analysisContext.analyze(typeReference, AnalysisMode.PARTIAL)
|
||||||
val kotlinType = bindingContext[BindingContext.TYPE, typeReference]
|
val kotlinType =
|
||||||
?: ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE, typeReference.text)
|
if (declaration is KtParameter && declaration.isVarArg) {
|
||||||
|
// we want full Array<out T> type for parity with FIR implementation
|
||||||
|
bindingContext[BindingContext.VALUE_PARAMETER, declaration]?.returnType
|
||||||
|
} else {
|
||||||
|
bindingContext[BindingContext.TYPE, typeReference]
|
||||||
|
} ?: ErrorUtils.createErrorType(ErrorTypeKind.RETURN_TYPE, typeReference.text)
|
||||||
|
|
||||||
return kotlinType.toKtType(analysisContext)
|
return kotlinType.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -93,4 +93,10 @@ public class Fe10IdeNormalAnalysisSourceModuleDeclarationReturnTypeTestGenerated
|
|||||||
public void testTypeParameters() throws Exception {
|
public void testTypeParameters() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("varargParam.kt")
|
||||||
|
public void testVarargParam() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/varargParam.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -93,4 +93,10 @@ public class FirIdeDependentAnalysisSourceModuleDeclarationReturnTypeTestGenerat
|
|||||||
public void testTypeParameters() throws Exception {
|
public void testTypeParameters() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("varargParam.kt")
|
||||||
|
public void testVarargParam() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/varargParam.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -93,4 +93,10 @@ public class FirIdeNormalAnalysisSourceModuleDeclarationReturnTypeTestGenerated
|
|||||||
public void testTypeParameters() throws Exception {
|
public void testTypeParameters() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("varargParam.kt")
|
||||||
|
public void testVarargParam() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/varargParam.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -93,4 +93,10 @@ public class FirStandaloneNormalAnalysisSourceModuleDeclarationReturnTypeTestGen
|
|||||||
public void testTypeParameters() throws Exception {
|
public void testTypeParameters() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/typeParameters.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("varargParam.kt")
|
||||||
|
public void testVarargParam() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/declarationReturnType/varargParam.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -35,7 +35,11 @@ public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
|
|||||||
withValidityAssertion { analysisSession.expressionTypeProvider.getKtExpressionType(this) }
|
withValidityAssertion { analysisSession.expressionTypeProvider.getKtExpressionType(this) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the return type of the given [KtDeclaration] as [KtType]
|
* Returns the return type of the given [KtDeclaration] as [KtType].
|
||||||
|
*
|
||||||
|
* IMPORTANT: For `vararg foo: T` parameter returns full `Array<out T>` type (unlike
|
||||||
|
* [KtValueParameterSymbol.returnType][org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol.returnType],
|
||||||
|
* which returns `T`).
|
||||||
*/
|
*/
|
||||||
public fun KtDeclaration.getReturnKtType(): KtType =
|
public fun KtDeclaration.getReturnKtType(): KtType =
|
||||||
withValidityAssertion { analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this) }
|
withValidityAssertion { analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this) }
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class Foo(vararg constructorValues: String)
|
||||||
|
|
||||||
|
fun test(vararg values: String) {}
|
||||||
|
|
||||||
|
fun test(vararg primitiveValues: Int) {}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
Foo@(1,1)
|
||||||
|
Foo@(1,10) : Foo
|
||||||
|
constructorValues@(1,11) : kotlin.Array<out kotlin.String>
|
||||||
|
test@(3,1) : kotlin.Unit
|
||||||
|
values@(3,10) : kotlin.Array<out kotlin.String>
|
||||||
|
test@(5,1) : kotlin.Unit
|
||||||
|
primitiveValues@(5,10) : kotlin.IntArray
|
||||||
Reference in New Issue
Block a user