[AA] getExpectedType should not calculate expression type
if property doesn't specify explicit type, property's return type would be calculated by provided initializer ^KT-62588 fixed Merge-request: KT-MR-12564 Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
This commit is contained in:
+2
@@ -317,6 +317,7 @@ internal class KtFirExpressionTypeProvider(
|
||||
// Given: `val x: T = expression`
|
||||
// Expected type of `expression` is `T`
|
||||
val property = expression.unwrapQualified<KtProperty> { property, expr -> property.initializer == expr } ?: return null
|
||||
if (property.typeReference == null) return null
|
||||
return getReturnTypeForKtDeclaration(property).nonErrorTypeOrNull()
|
||||
}
|
||||
|
||||
@@ -329,6 +330,7 @@ internal class KtFirExpressionTypeProvider(
|
||||
// which may raise an exception if we attempt to retrieve, e.g., callable declaration from it.
|
||||
return null
|
||||
}
|
||||
if (function.typeReference == null) return null
|
||||
return getReturnTypeForKtDeclaration(function).nonErrorTypeOrNull()
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -280,6 +280,12 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyDeclarationNoExplicitType.kt")
|
||||
public void testPropertyDeclarationNoExplicitType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclarationNoExplicitType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyDeclarationQualified.kt")
|
||||
public void testPropertyDeclarationQualified() throws Exception {
|
||||
|
||||
+6
@@ -280,6 +280,12 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyDeclarationNoExplicitType.kt")
|
||||
public void testPropertyDeclarationNoExplicitType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclarationNoExplicitType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyDeclarationQualified.kt")
|
||||
public void testPropertyDeclarationQualified() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user