diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index d90579d9d6e..b5d80bfd611 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1807,6 +1807,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + @TestMetadata("inapplicableCollectionSet.kt") + public void testInapplicableCollectionSet() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt"); + } + @TestMetadata("InnerClassInAnonymous.kt") public void testInnerClassInAnonymous() throws Exception { runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt"); diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt new file mode 100644 index 00000000000..50b799c254c --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt @@ -0,0 +1,32 @@ +class Flaf { + constructor(javaName: String) /* primary */ { + super/*Any*/() + /* () */ + + } + + val javaName: String + field = javaName + get + + private val INSTANCES: MutableMap + field = mutableMapOf() + private get + + fun forJavaName(javaName: String): Flaf { + var result: Flaf? = .().get(key = javaName) + when { + EQEQ(arg0 = result, arg1 = null) -> { // BLOCK + result = .().get(key = javaName.toString() + "_alternative") + when { + EQEQ(arg0 = result, arg1 = null) -> { // BLOCK + result = Flaf(javaName = javaName) + } + } + error("") /* ErrorCallExpression */javaName; result; + } + } + return result + } + +} diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt new file mode 100644 index 00000000000..4a37c0bf4a6 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt @@ -0,0 +1,82 @@ +FILE fqName: fileName:/inapplicableCollectionSet.kt + CLASS CLASS name:Flaf modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Flaf + CONSTRUCTOR visibility:public <> (javaName:kotlin.String) returnType:.Flaf [primary] + VALUE_PARAMETER name:javaName index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Flaf modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:javaName visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:javaName type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'javaName: kotlin.String declared in .Flaf.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Flaf) returnType:kotlin.String + correspondingProperty: PROPERTY name:javaName visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Flaf + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Flaf' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:javaName type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Flaf declared in .Flaf.' type=.Flaf origin=null + PROPERTY name:INSTANCES visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:INSTANCES type:kotlin.collections.MutableMap.Flaf> visibility:private [final] + EXPRESSION_BODY + CALL 'public final fun mutableMapOf (): kotlin.collections.MutableMap [inline] declared in kotlin.collections' type=kotlin.collections.MutableMap.Flaf> origin=null + : kotlin.String + : .Flaf + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.Flaf) returnType:kotlin.collections.MutableMap.Flaf> + correspondingProperty: PROPERTY name:INSTANCES visibility:private modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Flaf + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:INSTANCES type:kotlin.collections.MutableMap.Flaf> visibility:private [final]' type=kotlin.collections.MutableMap.Flaf> origin=null + receiver: GET_VAR ': .Flaf declared in .Flaf.' type=.Flaf origin=null + FUN name:forJavaName visibility:public modality:FINAL <> ($this:.Flaf, javaName:kotlin.String) returnType:.Flaf + $this: VALUE_PARAMETER name: type:.Flaf + VALUE_PARAMETER name:javaName index:0 type:kotlin.String + BLOCK_BODY + VAR name:result type:.Flaf? [var] + CALL 'public abstract fun get (key: K of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? [fake_override,operator] declared in kotlin.collections.MutableMap' type=.Flaf? origin=null + $this: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + WHEN type=kotlin.Unit origin=IF + 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: GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: BLOCK type=kotlin.Unit origin=null + SET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=kotlin.Unit origin=EQ + CALL 'public abstract fun get (key: K of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? [fake_override,operator] declared in kotlin.collections.MutableMap' type=.Flaf? origin=null + $this: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: STRING_CONCATENATION type=kotlin.String + CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.String' type=kotlin.String origin=null + $this: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + CONST String type=kotlin.String value="_alternative" + WHEN type=kotlin.Unit origin=IF + 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: GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: BLOCK type=kotlin.Unit origin=null + SET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=kotlin.Unit origin=EQ + CONSTRUCTOR_CALL 'public constructor (javaName: kotlin.String) [primary] declared in .Flaf' type=.Flaf origin=null + javaName: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit + GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): .Flaf declared in .Flaf' + GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt new file mode 100644 index 00000000000..a423b0f883b --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt @@ -0,0 +1,20 @@ +// WITH_RUNTIME +// FULL_JDK + +class Flaf(val javaName: String) { + + private val INSTANCES = mutableMapOf() + + fun forJavaName(javaName: String): Flaf { + var result: Flaf? = INSTANCES[javaName] + if (result == null) { + result = INSTANCES["${javaName}_alternative"] + if (result == null) { + result = Flaf(javaName) + } + INSTANCES[javaName] = result + } + return result + } + +} diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt.txt new file mode 100644 index 00000000000..678b6459f08 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt.txt @@ -0,0 +1,32 @@ +class Flaf { + constructor(javaName: String) /* primary */ { + super/*Any*/() + /* () */ + + } + + val javaName: String + field = javaName + get + + private val INSTANCES: MutableMap + field = mutableMapOf() + private get + + fun forJavaName(javaName: String): Flaf { + var result: Flaf? = .().get(key = javaName) + when { + EQEQ(arg0 = result, arg1 = null) -> { // BLOCK + result = .().get(key = javaName + "_alternative") + when { + EQEQ(arg0 = result, arg1 = null) -> { // BLOCK + result = Flaf(javaName = javaName) + } + } + .().set(key = javaName, value = result) + } + } + return result + } + +} diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.txt new file mode 100644 index 00000000000..961aaa9f82b --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.txt @@ -0,0 +1,85 @@ +FILE fqName: fileName:/inapplicableCollectionSet.kt + CLASS CLASS name:Flaf modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Flaf + CONSTRUCTOR visibility:public <> (javaName:kotlin.String) returnType:.Flaf [primary] + VALUE_PARAMETER name:javaName index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Flaf modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:javaName visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:javaName type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'javaName: kotlin.String declared in .Flaf.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Flaf) returnType:kotlin.String + correspondingProperty: PROPERTY name:javaName visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Flaf + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Flaf' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:javaName type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .Flaf declared in .Flaf.' type=.Flaf origin=null + PROPERTY name:INSTANCES visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:INSTANCES type:kotlin.collections.MutableMap.Flaf> visibility:private [final] + EXPRESSION_BODY + CALL 'public final fun mutableMapOf (): kotlin.collections.MutableMap [inline] declared in kotlin.collections' type=kotlin.collections.MutableMap.Flaf> origin=null + : kotlin.String + : .Flaf + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.Flaf) returnType:kotlin.collections.MutableMap.Flaf> + correspondingProperty: PROPERTY name:INSTANCES visibility:private modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Flaf + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:INSTANCES type:kotlin.collections.MutableMap.Flaf> visibility:private [final]' type=kotlin.collections.MutableMap.Flaf> origin=null + receiver: GET_VAR ': .Flaf declared in .Flaf.' type=.Flaf origin=null + FUN name:forJavaName visibility:public modality:FINAL <> ($this:.Flaf, javaName:kotlin.String) returnType:.Flaf + $this: VALUE_PARAMETER name: type:.Flaf + VALUE_PARAMETER name:javaName index:0 type:kotlin.String + BLOCK_BODY + VAR name:result type:.Flaf? [var] + CALL 'public abstract fun get (key: K of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? [fake_override,operator] declared in kotlin.collections.MutableMap' type=.Flaf? origin=GET_ARRAY_ELEMENT + $this: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + WHEN type=kotlin.Unit origin=IF + 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: GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: BLOCK type=kotlin.Unit origin=null + SET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=kotlin.Unit origin=EQ + CALL 'public abstract fun get (key: K of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? [fake_override,operator] declared in kotlin.collections.MutableMap' type=.Flaf? origin=GET_ARRAY_ELEMENT + $this: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: STRING_CONCATENATION type=kotlin.String + GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + CONST String type=kotlin.String value="_alternative" + WHEN type=kotlin.Unit origin=IF + 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: GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: BLOCK type=kotlin.Unit origin=null + SET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=kotlin.Unit origin=EQ + CONSTRUCTOR_CALL 'public constructor (javaName: kotlin.String) [primary] declared in .Flaf' type=.Flaf origin=null + javaName: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + CALL 'public final fun set (key: K of kotlin.collections.set, value: V of kotlin.collections.set): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=EQ + : kotlin.String + : .Flaf + $receiver: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + value: GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): .Flaf declared in .Flaf' + GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 9e5ac0cf31b..f16381fb6e9 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1806,6 +1806,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + @TestMetadata("inapplicableCollectionSet.kt") + public void testInapplicableCollectionSet() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.kt"); + } + @TestMetadata("InnerClassInAnonymous.kt") public void testInnerClassInAnonymous() throws Exception { runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt");