From 2e660ef62aa988fbb23ef5e9dc56528ee84ed01b Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Mon, 18 Jan 2021 00:18:38 -0800 Subject: [PATCH] Raw FIR: use lambda parameter type if available --- .../lightTree/converter/ExpressionsConverter.kt | 3 +-- .../jetbrains/kotlin/fir/builder/RawFirBuilder.kt | 4 ++-- .../destructuringInLambdas/complexInference.fir.kt | 6 +++--- .../inferredFunctionalType.fir.kt | 2 +- .../destructuringInLambdas/noExpectedType.fir.kt | 14 +++++++------- .../destructuringInLambdas/simple.fir.kt | 6 +++--- .../destructuringInLambdas/underscore.fir.kt | 4 ++-- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 670c637fe09..d95bd4e607c 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -38,7 +38,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.FirTypeRef -import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType @@ -155,7 +154,7 @@ class ExpressionsConverter( val multiParameter = buildValueParameter { session = baseSession origin = FirDeclarationOrigin.Source - returnTypeRef = buildImplicitTypeRef() + returnTypeRef = valueParameter.firValueParameter.returnTypeRef this.name = name symbol = FirVariableSymbol(name) defaultValue = null diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 6b70d454b89..7c23143efdb 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1106,7 +1106,7 @@ class RawFirBuilder( source = valueParameter.toFirSourceElement() session = baseSession origin = FirDeclarationOrigin.Source - returnTypeRef = buildImplicitTypeRef { + returnTypeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef { source = multiDeclaration.toFirSourceElement(FirFakeSourceElementKind.ImplicitTypeRef) } this.name = name @@ -1124,7 +1124,7 @@ class RawFirBuilder( ) { toFirOrImplicitType() } multiParameter } else { - val typeRef = buildImplicitTypeRef { + val typeRef = valueParameter.typeReference?.convertSafe() ?: buildImplicitTypeRef { source = implicitTypeRefSource } valueParameter.toFirValueParameter(typeRef) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt index b12e1a7dcd1..e9d09e341af 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/complexInference.fir.kt @@ -9,9 +9,9 @@ fun foo(y: Y, x: (X, Y) -> Unit) {} fun bar(aInstance: A, bInstance: B) { foo("") { - (a, b): A, c -> - a checkType { _() } - b checkType { _() } + (a, b): A, c -> + a checkType { _() } + b checkType { _() } c checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt index 43835ece222..0fcfc1b4a2d 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/inferredFunctionalType.fir.kt @@ -27,7 +27,7 @@ fun bar(aList: List) { b checkType { _() } } - aList.foo { (a, b): B -> + aList.foo { (a, b): B -> b checkType { _() } a checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt index 270d1deee1d..4fec1861ca3 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.fir.kt @@ -4,23 +4,23 @@ data class A(val x: Int, val y: String) fun bar() { - val x = { (a, b): A -> - a checkType { _() } - b checkType { _() } + val x = { (a, b): A -> + a checkType { _() } + b checkType { _() } } x checkType { _<(A) -> Unit>() } - val y = { (a: Int, b): A -> + val y = { (a: Int, b): A -> a checkType { _() } - b checkType { _() } + b checkType { _() } } y checkType { _<(A) -> Unit>() } - val y2 = { (a: Number, b): A -> + val y2 = { (a: Number, b): A -> a checkType { _() } - b checkType { _() } + b checkType { _() } } y2 checkType { _<(A) -> Unit>() } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt index 41783ca7cee..1115485d97c 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.fir.kt @@ -47,8 +47,8 @@ fun bar() { b checkType { _() } } - foo { (a, b): B -> - a checkType { _() } - b checkType { _() } + foo { (a, b): B -> + a checkType { _() } + b checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt index 0dda6673162..afdf43b95f5 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/underscore.fir.kt @@ -56,8 +56,8 @@ fun bar() { b checkType { _() } } - foo { (_, b): B -> + foo { (_, b): B -> _.hashCode() - b checkType { _() } + b checkType { _() } } }