[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
@@ -191,6 +191,8 @@ class KtFe10ExpressionTypeProvider(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parentExpression.typeReference == null) return null
|
||||||
|
|
||||||
val bindingContext = analysisContext.analyze(parentExpression)
|
val bindingContext = analysisContext.analyze(parentExpression)
|
||||||
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, parentExpression]
|
val descriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, parentExpression]
|
||||||
if (descriptor is CallableDescriptor) {
|
if (descriptor is CallableDescriptor) {
|
||||||
|
|||||||
+6
@@ -280,6 +280,12 @@ public class Fe10IdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerate
|
|||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
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
|
@Test
|
||||||
@TestMetadata("propertyDeclarationQualified.kt")
|
@TestMetadata("propertyDeclarationQualified.kt")
|
||||||
public void testPropertyDeclarationQualified() throws Exception {
|
public void testPropertyDeclarationQualified() throws Exception {
|
||||||
|
|||||||
+2
@@ -317,6 +317,7 @@ internal class KtFirExpressionTypeProvider(
|
|||||||
// Given: `val x: T = expression`
|
// Given: `val x: T = expression`
|
||||||
// Expected type of `expression` is `T`
|
// Expected type of `expression` is `T`
|
||||||
val property = expression.unwrapQualified<KtProperty> { property, expr -> property.initializer == expr } ?: return null
|
val property = expression.unwrapQualified<KtProperty> { property, expr -> property.initializer == expr } ?: return null
|
||||||
|
if (property.typeReference == null) return null
|
||||||
return getReturnTypeForKtDeclaration(property).nonErrorTypeOrNull()
|
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.
|
// which may raise an exception if we attempt to retrieve, e.g., callable declaration from it.
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
if (function.typeReference == null) return null
|
||||||
return getReturnTypeForKtDeclaration(function).nonErrorTypeOrNull()
|
return getReturnTypeForKtDeclaration(function).nonErrorTypeOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -280,6 +280,12 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
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
|
@Test
|
||||||
@TestMetadata("propertyDeclarationQualified.kt")
|
@TestMetadata("propertyDeclarationQualified.kt")
|
||||||
public void testPropertyDeclarationQualified() throws Exception {
|
public void testPropertyDeclarationQualified() throws Exception {
|
||||||
|
|||||||
+6
@@ -280,6 +280,12 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
|
|||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
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
|
@Test
|
||||||
@TestMetadata("propertyDeclarationQualified.kt")
|
@TestMetadata("propertyDeclarationQualified.kt")
|
||||||
public void testPropertyDeclarationQualified() throws Exception {
|
public void testPropertyDeclarationQualified() throws Exception {
|
||||||
|
|||||||
+6
@@ -280,6 +280,12 @@ public class FirStandaloneNormalAnalysisSourceModuleExpectedExpressionTypeTestGe
|
|||||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/propertyDeclaration.kt");
|
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
|
@Test
|
||||||
@TestMetadata("propertyDeclarationQualified.kt")
|
@TestMetadata("propertyDeclarationQualified.kt")
|
||||||
public void testPropertyDeclarationQualified() throws Exception {
|
public void testPropertyDeclarationQualified() throws Exception {
|
||||||
|
|||||||
+1
-4
@@ -1,5 +1,2 @@
|
|||||||
expression: av
|
expression: av
|
||||||
expected type: KtUsualClassType:
|
expected type: null
|
||||||
annotationsList: []
|
|
||||||
ownTypeArguments: []
|
|
||||||
type: kotlin/String
|
|
||||||
|
|||||||
+1
-13
@@ -2,16 +2,4 @@ expression: { a: Int ->
|
|||||||
val b = 1
|
val b = 1
|
||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
expected type: KtFunctionalType:
|
expected type: null
|
||||||
annotationsList: []
|
|
||||||
ownTypeArguments: [
|
|
||||||
KtUsualClassType:
|
|
||||||
annotationsList: []
|
|
||||||
ownTypeArguments: []
|
|
||||||
type: kotlin/Int
|
|
||||||
KtUsualClassType:
|
|
||||||
annotationsList: []
|
|
||||||
ownTypeArguments: []
|
|
||||||
type: kotlin/Int
|
|
||||||
]
|
|
||||||
type: kotlin/Function1<kotlin/Int, kotlin/Int>
|
|
||||||
|
|||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
var y = "<caret>"
|
||||||
|
}
|
||||||
|
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
expression: ""
|
||||||
|
expected type: null
|
||||||
+1
-4
@@ -1,5 +1,2 @@
|
|||||||
expression: av
|
expression: av
|
||||||
expected type: KtUsualClassType:
|
expected type: null
|
||||||
annotationsList: []
|
|
||||||
ownTypeArguments: []
|
|
||||||
type: kotlin/String
|
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
expression: av
|
expression: av
|
||||||
expected type: KtUsualClassType:
|
expected type: KtIntersectionType:
|
||||||
annotationsList: []
|
annotationsList: []
|
||||||
ownTypeArguments: []
|
type: it(kotlin/Int & kotlin/String)
|
||||||
type: kotlin/Any
|
|
||||||
|
|||||||
Reference in New Issue
Block a user