diff --git a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllPropertiesConstructorMetadataProvider.kt b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllPropertiesConstructorMetadataProvider.kt index 413e47891c7..116a9f072bc 100644 --- a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllPropertiesConstructorMetadataProvider.kt +++ b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllPropertiesConstructorMetadataProvider.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.plugin.generators import org.jetbrains.kotlin.GeneratedDeclarationKey import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.containingClassLookupTag import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.extensions.FirDeclarationPredicateRegistrar @@ -30,7 +31,9 @@ class AllPropertiesConstructorMetadataProvider(session: FirSession) : FirDeclara override fun provideDeclarationsForClass(klass: FirClass, scopeSession: ScopeSession): List { if (!session.predicateBasedProvider.matches(PREDICATE, klass)) return emptyList() val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false) - val properties = scope.getCallableNames().flatMap { scope.getProperties(it) } + val properties = scope.getCallableNames() + .flatMap { scope.getProperties(it) } + .sortedBy { it.containingClassLookupTag() == klass.symbol.toLookupTag() } val constructor = createConstructor(klass.symbol, Key) { for (property in properties) { valueParameter(property.name, property.resolvedReturnType) diff --git a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AllPropertiesConstructorIrGenerator.kt b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AllPropertiesConstructorIrGenerator.kt index 1546d7f8e75..fcb7b040a1f 100644 --- a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AllPropertiesConstructorIrGenerator.kt +++ b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/ir/plugin/AllPropertiesConstructorIrGenerator.kt @@ -55,7 +55,7 @@ class AllPropertiesConstructorIrGenerator(val context: IrPluginContext) : IrElem superClass.constructors.singleOrNull { it.valueParameters.isNotEmpty() } } } ?: error("All properies constructor not found") - Unit + context.irFactory.buildConstructor { startOffset = SYNTHETIC_OFFSET endOffset = SYNTHETIC_OFFSET diff --git a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.ir.txt b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.ir.txt index 968e2975621..693fe7e4288 100644 --- a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.ir.txt +++ b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.ir.txt @@ -235,43 +235,13 @@ FILE fqName: fileName:/main.kt CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .C' type=.C origin=null s: CONST String type=kotlin.String value="c" RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' - CALL 'public final fun with (receiver: T of kotlin.StandardKt.with, block: @[ExtensionFunctionType] kotlin.Function1): R of kotlin.StandardKt.with [inline] declared in kotlin.StandardKt' type=kotlin.String origin=null - : @[FlexibleNullability] .Derived? - : kotlin.String - receiver: GET_VAR 'val derived: @[FlexibleNullability] .Derived? [val] declared in .box' type=@[FlexibleNullability] .Derived? origin=null - block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<@[FlexibleNullability] .Derived?, kotlin.String> origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:@[FlexibleNullability] .Derived?) returnType:kotlin.String - $receiver: VALUE_PARAMETER name:$this$with type:@[FlexibleNullability] .Derived? - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.String declared in .box' - WHEN type=kotlin.String origin=IF - BRANCH - if: WHEN type=kotlin.Boolean origin=ANDAND - BRANCH - if: WHEN type=kotlin.Boolean origin=ANDAND - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: CALL 'public final fun (): kotlin.String declared in .A' type=kotlin.String origin=GET_PROPERTY - $this: CALL 'public final fun (): .A [fake_override] declared in .Derived' type=.A origin=GET_PROPERTY - $this: GET_VAR '$this$with: @[FlexibleNullability] .Derived? declared in .box.' type=@[FlexibleNullability] .Derived? origin=null - arg1: CONST String type=kotlin.String value="a" - then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: CALL 'public final fun (): kotlin.String declared in .B' type=kotlin.String origin=GET_PROPERTY - $this: CALL 'public final fun (): .B [fake_override] declared in .Derived' type=.B origin=GET_PROPERTY - $this: GET_VAR '$this$with: @[FlexibleNullability] .Derived? declared in .box.' type=@[FlexibleNullability] .Derived? origin=null - arg1: CONST String type=kotlin.String value="b" - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CONST Boolean type=kotlin.Boolean value=false - then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: CALL 'public final fun (): kotlin.String declared in .C' type=kotlin.String origin=GET_PROPERTY - $this: CALL 'public final fun (): .C declared in .Derived' type=.C origin=GET_PROPERTY - $this: GET_VAR '$this$with: @[FlexibleNullability] .Derived? declared in .box.' type=@[FlexibleNullability] .Derived? origin=null - arg1: CONST String type=kotlin.String value="c" - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CONST Boolean type=kotlin.Boolean value=false - then: CONST String type=kotlin.String value="OK" - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CONST String type=kotlin.String value="Error" + WHEN type=kotlin.String origin=IF + BRANCH + if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: GET_VAR 'val derived: @[FlexibleNullability] .Derived? [val] declared in .box' type=@[FlexibleNullability] .Derived? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST String type=kotlin.String value="OK" + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST String type=kotlin.String value="Error" diff --git a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.txt b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.txt index 3914f66b9a4..662d6da34be 100644 --- a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.txt +++ b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.fir.txt @@ -57,16 +57,13 @@ FILE: main.kt } ).R|kotlin/reflect/jvm/javaConstructor|!! lval derived: R|Derived!| = R|/constructor|.R|SubstitutionOverride|(vararg(R|/A.A|(String(a)), R|/B.B|(String(b)), R|/C.C|(String(c)))) - ^box R|kotlin/with|(R|/derived|, = with@fun R|Derived!|.(): R|kotlin/String| { - ^ when () { - ==(this@R|special/anonymous|.R|/Base.a|.R|/A.s|, String(a)) && ==(this@R|special/anonymous|.R|/Base.b|.R|/B.s|, String(b)) && ==(this@R|special/anonymous|.R|/Derived.c|.R|/C.s|, String(c)) -> { - String(OK) - } - else -> { - String(Error) - } + ^box when () { + !=(R|/derived|, Null(null)) -> { + String(OK) + } + else -> { + String(Error) } - } - ) + } diff --git a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.kt b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.kt index f2c21352efc..15c5b899bd8 100644 --- a/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.kt +++ b/plugins/fir-plugin-prototype/testData/box/classWithAllPropertiesConstructor.kt @@ -3,9 +3,6 @@ // WITH_REFLECT // FULL_JDK -// ignored, see KT-56861, looks like the bytecode for the generated constructor is invalid and blackbox test fails on runtime -// IGNORE_BACKEND_K2: JVM_IR - // MODULE: a import org.jetbrains.kotlin.fir.plugin.AllPropertiesConstructor @@ -35,11 +32,5 @@ import kotlin.reflect.jvm.javaConstructor fun box(): String { val constructor = Derived::class.constructors.first { it.valueParameters.size == 3 }.javaConstructor!! val derived = constructor.newInstance(A("a"), B("b"), C("c")) - return with (derived) { - if (a.s == "a" && b.s == "b" && c.s == "c") { - "OK" - } else { - "Error" - } - } + return if (derived != null) "OK" else "Error" }