From 8c21f04bf479462eb6368b760af182244d5428d7 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 20 Feb 2020 13:24:10 +0300 Subject: [PATCH] FIR2IR: determine type parameters before value parameters Type parameters can be referred from value parameters, so we should determine them earlier to be able to set their indexes --- .../kotlin/fir/backend/Fir2IrDeclarationStorage.kt | 6 +++--- .../codegen/box/binaryOp/eqNullableDoublesToIntWithTP.kt | 1 - compiler/testData/codegen/box/finally/kt4134.kt | 1 - .../codegen/box/javaInterop/notNullAssertions/mapPut.kt | 1 - .../testData/codegen/box/jvmField/topLevelFieldReference.kt | 1 - .../testData/codegen/box/jvmField/writeFieldReference.kt | 1 - .../box/operatorConventions/genericArrayAccessCall.kt | 1 - .../typeParameterWithPrimitiveNumericSupertype.fir.txt | 2 +- 8 files changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 0c54810dc0b..fb783f6307a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -398,6 +398,9 @@ class Fir2IrDeclarationStorage( private fun T.declareParameters(function: FirFunction<*>?, containingClass: IrClass?, isStatic: Boolean) { val parent = this + if (function is FirSimpleFunction) { + setTypeParameters(function) + } if (function is FirDefaultPropertySetter) { val type = function.valueParameters.first().returnTypeRef.toIrType(session, this@Fir2IrDeclarationStorage) declareDefaultSetterParameter(type) @@ -408,9 +411,6 @@ class Fir2IrDeclarationStorage( } if (function !is FirConstructor) { val thisOrigin = IrDeclarationOrigin.DEFINED - if (function is FirSimpleFunction) { - setTypeParameters(function) - } val receiverTypeRef = function?.receiverTypeRef if (receiverTypeRef != null) { extensionReceiverParameter = receiverTypeRef.convertWithOffsets { startOffset, endOffset -> diff --git a/compiler/testData/codegen/box/binaryOp/eqNullableDoublesToIntWithTP.kt b/compiler/testData/codegen/box/binaryOp/eqNullableDoublesToIntWithTP.kt index 53059a1a412..060e5a3b202 100644 --- a/compiler/testData/codegen/box/binaryOp/eqNullableDoublesToIntWithTP.kt +++ b/compiler/testData/codegen/box/binaryOp/eqNullableDoublesToIntWithTP.kt @@ -2,7 +2,6 @@ // It doesn't work on JS due to how numbers are represented, but it could be changed in the future. // IGNORE_BACKEND: JS // IGNORE_BACKEND: JS_IR -// IGNORE_BACKEND_FIR: JVM_IR fun eq_double_any(a: A, b: B) = a == b diff --git a/compiler/testData/codegen/box/finally/kt4134.kt b/compiler/testData/codegen/box/finally/kt4134.kt index 5fa4f8f2f95..24e4750d089 100644 --- a/compiler/testData/codegen/box/finally/kt4134.kt +++ b/compiler/testData/codegen/box/finally/kt4134.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun io(s: R, a: (R) -> T): T { try { return a(s) diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt index 3c82f27c6fc..a9331b0a576 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME fun foo(k: K, v: V) { diff --git a/compiler/testData/codegen/box/jvmField/topLevelFieldReference.kt b/compiler/testData/codegen/box/jvmField/topLevelFieldReference.kt index 8d71f69a0ae..d865a22d26c 100644 --- a/compiler/testData/codegen/box/jvmField/topLevelFieldReference.kt +++ b/compiler/testData/codegen/box/jvmField/topLevelFieldReference.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/jvmField/writeFieldReference.kt b/compiler/testData/codegen/box/jvmField/writeFieldReference.kt index 649d74dae15..1475872288e 100644 --- a/compiler/testData/codegen/box/jvmField/writeFieldReference.kt +++ b/compiler/testData/codegen/box/jvmField/writeFieldReference.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/operatorConventions/genericArrayAccessCall.kt b/compiler/testData/codegen/box/operatorConventions/genericArrayAccessCall.kt index 6d3363d5ed0..2468d44bc69 100644 --- a/compiler/testData/codegen/box/operatorConventions/genericArrayAccessCall.kt +++ b/compiler/testData/codegen/box/operatorConventions/genericArrayAccessCall.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // KJS_WITH_FULL_RUNTIME diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.txt index 44c07059e06..a6c3321c37a 100644 --- a/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.txt +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/typeParameterWithPrimitiveNumericSupertype.fir.txt @@ -86,7 +86,7 @@ FILE fqName: fileName:/typeParameterWithPrimitiveNumericSupertype.kt then: CONST Boolean type=kotlin.Boolean value=false FUN name:test5 visibility:public modality:FINAL (x:kotlin.Any, y:R of .test5) returnType:kotlin.Boolean TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Float?] - TYPE_PARAMETER name:R index:0 variance: superTypes:[T of .test5] + TYPE_PARAMETER name:R index:1 variance: superTypes:[T of .test5] VALUE_PARAMETER name:x index:0 type:kotlin.Any VALUE_PARAMETER name:y index:1 type:R of .test5 BLOCK_BODY