From b7a99eca55dd650f7ecb1e92e6464ea410f7b1e8 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Thu, 19 Aug 2021 22:16:32 -0700 Subject: [PATCH] FIR IDE: expected type of lambdas and block expression --- .../components/KtFirExpressionTypeProvider.kt | 59 +++++++++++++---- .../idea/frontend/api/fir/utils/firUtils.kt | 16 +++-- .../functionExpressionBodyBlockExpression.kt | 8 +++ .../functionExpressionBodyBlockExpression.txt | 9 +++ .../functionNamedlParam.kt | 2 - .../functionNamedlParam.txt | 2 +- .../lambdaWithExplicitTypeFromVariable.kt | 3 + .../lambdaWithExplicitTypeFromVariable.txt | 4 ++ .../lambdaWithoutReturnNorExplicitType.kt | 4 ++ .../lambdaWithoutReturnNorExplicitType.txt | 5 ++ .../propertyDeclarationWithSafeCast.kt | 3 + .../propertyDeclarationWithSafeCast.txt | 2 + .../propertyDeclarationWithTypeCast.kt | 3 + .../propertyDeclarationWithTypeCast.txt | 2 + .../components/expectedExpressionType/sam.kt | 1 + .../components/expectedExpressionType/sam.txt | 2 + .../expectedExpressionType/samAsArgument.kt | 5 ++ .../expectedExpressionType/samAsArgument.txt | 2 + .../samAsConstructorArgument.kt | 3 + .../samAsConstructorArgument.txt | 2 + .../expectedExpressionType/samAsReturn.kt | 3 + .../expectedExpressionType/samAsReturn.txt | 2 + .../samWithExplicitTypeFromProperty.kt | 1 + .../samWithExplicitTypeFromProperty.txt | 2 + .../expectedExpressionType/samWithTypeCast.kt | 1 + .../samWithTypeCast.txt | 2 + .../ExpectedExpressionTypeTestGenerated.java | 66 +++++++++++++++++++ 27 files changed, 192 insertions(+), 22 deletions(-) create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.txt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.kt create mode 100644 idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.txt diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt index bf6ce7c08b8..cbd28e3165b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt @@ -8,13 +8,12 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.components import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirLabel import org.jetbrains.kotlin.fir.FirPackageDirective -import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration -import org.jetbrains.kotlin.fir.declarations.FirFunction -import org.jetbrains.kotlin.fir.declarations.FirImport +import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isSuspend import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.fir.references.FirNamedReference +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.constructFunctionalType import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -59,28 +58,55 @@ internal class KtFirExpressionTypeProvider( } override fun getExpectedType(expression: PsiElement): KtType? { - val expectedType = getExpectedTypeByReturnExpression(expression) - ?: getExpressionTypeByIfOrBooleanCondition(expression) - ?: getExpectedTypeOfFunctionParameter(expression) - ?: getExpectedTypeOfInfixFunctionParameter(expression) - ?: getExpectedTypeByVariableAssignment(expression) - ?: getExpectedTypeByPropertyDeclaration(expression) - ?: getExpectedTypeByFunctionExpressionBody(expression) + val unwrapped = expression.unwrap() + val expectedType = getExpectedTypeByReturnExpression(unwrapped) + ?: getExpressionTypeByIfOrBooleanCondition(unwrapped) + ?: getExpectedTypeByTypeCast(unwrapped) + ?: getExpectedTypeOfFunctionParameter(unwrapped) + ?: getExpectedTypeOfInfixFunctionParameter(unwrapped) + ?: getExpectedTypeByVariableAssignment(unwrapped) + ?: getExpectedTypeByPropertyDeclaration(unwrapped) + ?: getExpectedTypeByFunctionExpressionBody(unwrapped) return expectedType.takeIf { it !is KtClassErrorType } } + private fun getExpectedTypeByTypeCast(expression: PsiElement): KtType? { + val typeCastExpression = + expression.unwrapQualified { castExpr, expr -> castExpr.left == expr } ?: return null + with(analysisSession) { + return typeCastExpression.right?.getKtType() + } + } + private fun getExpectedTypeOfFunctionParameter(expression: PsiElement): KtType? { - val (ktCallExpression, ktArgument) = expression.getFunctionCallAsWithThisAsParameter() ?: return null + val (ktCallExpression, argumentExpression) = expression.getFunctionCallAsWithThisAsParameter() ?: return null val firCall = ktCallExpression.getOrBuildFirSafe(firResolveState) ?: return null + + val callee = (firCall.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol + if (callee?.fir?.origin == FirDeclarationOrigin.SamConstructor) { + return (callee.fir as FirSimpleFunction).returnTypeRef.coneType.asKtType() + } + val arguments = firCall.argumentMapping ?: return null - val firParameterForExpression = arguments.entries.firstOrNull { (arg, _) -> arg.psi == ktArgument }?.value ?: return null + val firParameterForExpression = + arguments.entries.firstOrNull { (arg, _) -> + when (arg) { + // TODO: better to utilize. See `createArgumentMapping` in [KtFirCallResolver] + is FirLambdaArgumentExpression, is FirNamedArgumentExpression, is FirSpreadArgumentExpression -> + arg.psi == argumentExpression.parent + else -> + arg.psi == argumentExpression + } + }?.value ?: return null return firParameterForExpression.returnTypeRef.coneType.asKtType() } private fun PsiElement.getFunctionCallAsWithThisAsParameter(): KtCallWithArgument? { val valueArgument = unwrapQualified { valueArg, expr -> valueArg.getArgumentExpression() == expr } ?: return null - val argumentsList = valueArgument.parent as? KtValueArgumentList ?: return null - val callExpression = argumentsList.parent as? KtCallExpression ?: return null + val callExpression = + (valueArgument.parent as? KtValueArgumentList)?.parent as? KtCallExpression + ?: valueArgument.parent as? KtCallExpression // KtLambdaArgument + ?: return null val argumentExpression = valueArgument.getArgumentExpression() ?: return null return KtCallWithArgument(callExpression, argumentExpression) } @@ -131,6 +157,11 @@ internal class KtFirExpressionTypeProvider( // Given: `fun f(): T = expression` // Expected type of `expression` is `T` val function = expression.unwrapQualified { function, expr -> function.bodyExpression == expr } ?: return null + if (function.bodyBlockExpression != null) { + // Given `fun f(...): R { blockExpression }`, `{ blockExpression }` is mapped to the enclosing anonymous function, + // which may raise an exception if we attempt to retrieve, e.g., callable declaration from it. + return null + } return getReturnTypeForKtDeclaration(function) } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/firUtils.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/firUtils.kt index 803b1e0192f..337fa20b70b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/firUtils.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/firUtils.kt @@ -4,6 +4,7 @@ */ package org.jetbrains.kotlin.idea.frontend.api.fir.utils +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirRegularClass @@ -26,17 +27,22 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSimpleConstantVa import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtUnsupportedConstantValue import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability import org.jetbrains.kotlin.idea.references.FirReferenceResolveHelper -import org.jetbrains.kotlin.psi.KtAnnotatedExpression -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtLabeledExpression -import org.jetbrains.kotlin.psi.KtObjectLiteralExpression +import org.jetbrains.kotlin.psi.* + +internal fun PsiElement.unwrap(): PsiElement { + return when (this) { + is KtExpression -> this.unwrap() + else -> this + } +} internal fun KtExpression.unwrap(): KtExpression { return when (this) { is KtLabeledExpression -> baseExpression?.unwrap() is KtAnnotatedExpression -> baseExpression?.unwrap() is KtObjectLiteralExpression -> objectDeclaration - else -> null + is KtFunctionLiteral -> (parent as? KtLambdaExpression)?.unwrap() + else -> this } ?: this } diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.kt new file mode 100644 index 00000000000..efe3de27c9a --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.kt @@ -0,0 +1,8 @@ +val lam4 = fun(a: Int): String { + if (a < 5) return "5" + + if (a > 0) + return "1" + else + return "2" +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.txt new file mode 100644 index 00000000000..ade42d50d81 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.txt @@ -0,0 +1,9 @@ +expression: { + if (a < 5) return "5" + + if (a > 0) + return "1" + else + return "2" +} +expected type: null diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.kt index 3137a81affb..58db03d2a31 100644 --- a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.kt +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.kt @@ -1,5 +1,3 @@ -// FIX_ME: should work on non fully resolved calls - fun x() { toCall(1, z = av) } diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.txt index 53684a9cf4e..2e28a9c5a9b 100644 --- a/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.txt +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/functionNamedlParam.txt @@ -1,2 +1,2 @@ expression: av -expected type: null +expected type: kotlin/Boolean diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.kt new file mode 100644 index 00000000000..7087fd96c8b --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.kt @@ -0,0 +1,3 @@ +val x: () -> Unit = { + val (a, b) = listOf(1, 2) +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.txt new file mode 100644 index 00000000000..50fc4649fa9 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.txt @@ -0,0 +1,4 @@ +expression: { + val (a, b) = listOf(1, 2) +} +expected type: kotlin/Function0 diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.kt new file mode 100644 index 00000000000..56b2604d1b5 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.kt @@ -0,0 +1,4 @@ +val lam1 = { a: Int -> + val b = 1 + a + b +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.txt new file mode 100644 index 00000000000..75ed7511277 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.txt @@ -0,0 +1,5 @@ +expression: { a: Int -> + val b = 1 + a + b +} +expected type: kotlin/Function1 diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.kt new file mode 100644 index 00000000000..27aa777e56b --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.kt @@ -0,0 +1,3 @@ +fun foo(p0 : Any) { + val s = p0 as? String +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.txt new file mode 100644 index 00000000000..9183d3de6a6 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.txt @@ -0,0 +1,2 @@ +expression: p0 +expected type: kotlin/String? diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.kt new file mode 100644 index 00000000000..f4c083c941e --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.kt @@ -0,0 +1,3 @@ +fun foo(p0 : Any) { + val s = p0 as String +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.txt new file mode 100644 index 00000000000..32e97e38889 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.txt @@ -0,0 +1,2 @@ +expression: p0 +expected type: kotlin/String diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.kt new file mode 100644 index 00000000000..54d77cc5456 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.kt @@ -0,0 +1 @@ +val baz = java.lang.Runnable { /* SAM */ } diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.txt new file mode 100644 index 00000000000..1fc83cdbcef --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.txt @@ -0,0 +1,2 @@ +expression: { /* SAM */ } +expected type: java/lang/Runnable diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.kt new file mode 100644 index 00000000000..3ea1ea0be20 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.kt @@ -0,0 +1,5 @@ +fun runRunnable(r: java.lang.Runnable) = r() + +fun foo() { + runRunnable { /* Argument */ } +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.txt new file mode 100644 index 00000000000..eab63033e57 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.txt @@ -0,0 +1,2 @@ +expression: { /* Argument */ } +expected type: java/lang/Runnable diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.kt new file mode 100644 index 00000000000..1c2126d9e76 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.kt @@ -0,0 +1,3 @@ +fun test1() { + val thread1 = Thread({ println("hello1") }) +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.txt new file mode 100644 index 00000000000..e32f50453f0 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.txt @@ -0,0 +1,2 @@ +expression: { println("hello1") } +expected type: ft diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.kt new file mode 100644 index 00000000000..0ea95c3169a --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.kt @@ -0,0 +1,3 @@ +fun bar(): java.lang.Runnable { + return { /* Return */ } +} diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.txt new file mode 100644 index 00000000000..05e4e353a0c --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.txt @@ -0,0 +1,2 @@ +expression: { /* Return */ } +expected type: java/lang/Runnable diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.kt new file mode 100644 index 00000000000..582c19302c1 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.kt @@ -0,0 +1 @@ +val foo : java.lang.Runnable = { /* Variable */ } diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.txt new file mode 100644 index 00000000000..1e66890fae8 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.txt @@ -0,0 +1,2 @@ +expression: { /* Variable */ } +expected type: java/lang/Runnable diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.kt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.kt new file mode 100644 index 00000000000..6fd4937792b --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.kt @@ -0,0 +1 @@ +val a = { /* Type Cast */ } as java.lang.Runnable diff --git a/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.txt b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.txt new file mode 100644 index 00000000000..ffa555f7a29 --- /dev/null +++ b/idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.txt @@ -0,0 +1,2 @@ +expression: { /* Type Cast */ } +expected type: java/lang/Runnable diff --git a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/fir/frontend/api/components/ExpectedExpressionTypeTestGenerated.java b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/fir/frontend/api/components/ExpectedExpressionTypeTestGenerated.java index bfd7fd26d91..c98fc28aa41 100644 --- a/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/fir/frontend/api/components/ExpectedExpressionTypeTestGenerated.java +++ b/idea/idea-frontend-fir/tests/org/jetbrains/kotlin/idea/fir/frontend/api/components/ExpectedExpressionTypeTestGenerated.java @@ -30,6 +30,12 @@ public class ExpectedExpressionTypeTestGenerated extends AbstractExpectedExpress runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBody.kt"); } + @Test + @TestMetadata("functionExpressionBodyBlockExpression.kt") + public void testFunctionExpressionBodyBlockExpression() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/functionExpressionBodyBlockExpression.kt"); + } + @Test @TestMetadata("functionExpressionBodyQualified.kt") public void testFunctionExpressionBodyQualified() throws Exception { @@ -108,6 +114,18 @@ public class ExpectedExpressionTypeTestGenerated extends AbstractExpectedExpress runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/infixFunctionParamQualified.kt"); } + @Test + @TestMetadata("lambdaWithExplicitTypeFromVariable.kt") + public void testLambdaWithExplicitTypeFromVariable() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithExplicitTypeFromVariable.kt"); + } + + @Test + @TestMetadata("lambdaWithoutReturnNorExplicitType.kt") + public void testLambdaWithoutReturnNorExplicitType() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/lambdaWithoutReturnNorExplicitType.kt"); + } + @Test @TestMetadata("propertyDeclaration.kt") public void testPropertyDeclaration() throws Exception { @@ -120,6 +138,18 @@ public class ExpectedExpressionTypeTestGenerated extends AbstractExpectedExpress runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationQualified.kt"); } + @Test + @TestMetadata("propertyDeclarationWithSafeCast.kt") + public void testPropertyDeclarationWithSafeCast() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithSafeCast.kt"); + } + + @Test + @TestMetadata("propertyDeclarationWithTypeCast.kt") + public void testPropertyDeclarationWithTypeCast() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/propertyDeclarationWithTypeCast.kt"); + } + @Test @TestMetadata("propertyDeclarationWithTypeFromRHS.kt") public void testPropertyDeclarationWithTypeFromRHS() throws Exception { @@ -156,6 +186,42 @@ public class ExpectedExpressionTypeTestGenerated extends AbstractExpectedExpress runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/returnFromLambda.kt"); } + @Test + @TestMetadata("sam.kt") + public void testSam() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/sam.kt"); + } + + @Test + @TestMetadata("samAsArgument.kt") + public void testSamAsArgument() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsArgument.kt"); + } + + @Test + @TestMetadata("samAsConstructorArgument.kt") + public void testSamAsConstructorArgument() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsConstructorArgument.kt"); + } + + @Test + @TestMetadata("samAsReturn.kt") + public void testSamAsReturn() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/samAsReturn.kt"); + } + + @Test + @TestMetadata("samWithExplicitTypeFromProperty.kt") + public void testSamWithExplicitTypeFromProperty() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithExplicitTypeFromProperty.kt"); + } + + @Test + @TestMetadata("samWithTypeCast.kt") + public void testSamWithTypeCast() throws Exception { + runTest("idea/idea-frontend-fir/testData/components/expectedExpressionType/samWithTypeCast.kt"); + } + @Test @TestMetadata("variableAssignment.kt") public void testVariableAssignment() throws Exception {