From 5efabe063e8cf7dff10f5e1f46c3cd83c7c27744 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 28 Aug 2020 18:40:18 +0300 Subject: [PATCH] [FIR] Fix JVM mapped function callable id --- .../kotlin/fir/Fir2IrTextTestGenerated.java | 5 +++ .../fir/resolve/scopes/JvmMappedScopes.kt | 2 +- .../kotlin/fir/resolve/SupertypeUtils.kt | 2 +- .../scopes/impl/FirClassSubstitutionScope.kt | 2 +- .../codegen/box/sam/constructors/kt19251.kt | 1 - .../box/sam/constructors/kt19251_child.kt | 1 - .../ir/irText/firProblems/putIfAbsent.fir.txt | 35 +++++++++++++++++++ .../ir/irText/firProblems/putIfAbsent.kt | 9 +++++ .../ir/irText/firProblems/putIfAbsent.txt | 35 +++++++++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 5 +++ 10 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/ir/irText/firProblems/putIfAbsent.fir.txt create mode 100644 compiler/testData/ir/irText/firProblems/putIfAbsent.kt create mode 100644 compiler/testData/ir/irText/firProblems/putIfAbsent.txt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index fe62f134a11..c4218597a85 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1716,6 +1716,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { public void testFirBuilder() throws Exception { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + + @TestMetadata("putIfAbsent.kt") + public void testPutIfAbsent() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt"); + } } @TestMetadata("compiler/testData/ir/irText/lambdas") diff --git a/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt b/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt index 094490679a0..b5e5e070426 100644 --- a/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt +++ b/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt @@ -45,7 +45,7 @@ fun wrapScopeWithJvmMapped( (klass.symbol.constructType( klass.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }.toTypedArray(), false - ) as ConeClassLikeType).wrapSubstitutionScopeIfNeed(useSiteSession, jvmMappedScope, klass, scopeSession) + ) as ConeClassLikeType).wrapSubstitutionScopeIfNeed(useSiteSession, jvmMappedScope, klass, scopeSession, klass.classId) } } } else { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt index 76b71bcc958..065c96e38e8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt @@ -88,7 +88,7 @@ fun ConeClassLikeType.wrapSubstitutionScopeIfNeed( useSiteMemberScope: FirTypeScope, declaration: FirClassLikeDeclaration<*>, builder: ScopeSession, - derivedClassId: ClassId? = null + derivedClassId: ClassId? ): FirTypeScope { if (this.typeArguments.isEmpty()) return useSiteMemberScope return builder.getOrBuild(declaration.symbol, SubstitutionScopeKey(this)) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index 447a8c83011..28864935a28 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -45,7 +45,7 @@ class FirClassSubstitutionScope( constructor( session: FirSession, useSiteMemberScope: FirTypeScope, scopeSession: ScopeSession, substitution: Map, - skipPrivateMembers: Boolean, derivedClassId: ClassId? = null + skipPrivateMembers: Boolean, derivedClassId: ClassId? ) : this(session, useSiteMemberScope, scopeSession, substitutorByMap(substitution), skipPrivateMembers, derivedClassId) override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) { diff --git a/compiler/testData/codegen/box/sam/constructors/kt19251.kt b/compiler/testData/codegen/box/sam/constructors/kt19251.kt index d08ee898c2e..35948380cc2 100644 --- a/compiler/testData/codegen/box/sam/constructors/kt19251.kt +++ b/compiler/testData/codegen/box/sam/constructors/kt19251.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // SKIP_JDK6 // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/sam/constructors/kt19251_child.kt b/compiler/testData/codegen/box/sam/constructors/kt19251_child.kt index 98b0cec9e38..bfbf4f59870 100644 --- a/compiler/testData/codegen/box/sam/constructors/kt19251_child.kt +++ b/compiler/testData/codegen/box/sam/constructors/kt19251_child.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // SKIP_JDK6 // TARGET_BACKEND: JVM // WITH_RUNTIME diff --git a/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.txt b/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.txt new file mode 100644 index 00000000000..ae5f3b7ef46 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/putIfAbsent.fir.txt @@ -0,0 +1,35 @@ +FILE fqName: fileName:/putIfAbsent.kt + CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner + CONSTRUCTOR visibility:public <> () returnType:.Owner [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:FINAL ($this:.Owner, x:T of .Owner.foo, y:T of .Owner.foo) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.Owner + VALUE_PARAMETER name:x index:0 type:T of .Owner.foo + VALUE_PARAMETER name:y index:1 type:T of .Owner.foo + BLOCK_BODY + VAR name:map type:kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> [val] + CALL 'public final fun mutableMapOf (): kotlin.collections.MutableMap [inline] declared in kotlin.collections' type=kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> origin=null + : T of .Owner.foo + : T of .Owner.foo + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun putIfAbsent (p0: K of kotlin.collections.MutableMap, p1: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=T of .Owner.foo? origin=null + $this: GET_VAR 'val map: kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> [val] declared in .Owner.foo' type=kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> origin=null + p0: GET_VAR 'x: T of .Owner.foo declared in .Owner.foo' type=T of .Owner.foo origin=null + p1: GET_VAR 'y: T of .Owner.foo declared in .Owner.foo' type=T of .Owner.foo 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/putIfAbsent.kt b/compiler/testData/ir/irText/firProblems/putIfAbsent.kt new file mode 100644 index 00000000000..1a15f2b67cc --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/putIfAbsent.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// FULL_JDK + +class Owner { + fun foo(x: T, y: T) { + val map = mutableMapOf() + map.putIfAbsent(x, y) + } +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/firProblems/putIfAbsent.txt b/compiler/testData/ir/irText/firProblems/putIfAbsent.txt new file mode 100644 index 00000000000..f87593fec94 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/putIfAbsent.txt @@ -0,0 +1,35 @@ +FILE fqName: fileName:/putIfAbsent.kt + CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner + CONSTRUCTOR visibility:public <> () returnType:.Owner [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:FINAL ($this:.Owner, x:T of .Owner.foo, y:T of .Owner.foo) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.Owner + VALUE_PARAMETER name:x index:0 type:T of .Owner.foo + VALUE_PARAMETER name:y index:1 type:T of .Owner.foo + BLOCK_BODY + VAR name:map type:kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> [val] + CALL 'public final fun mutableMapOf (): kotlin.collections.MutableMap [inline] declared in kotlin.collections' type=kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> origin=null + : T of .Owner.foo + : T of .Owner.foo + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun putIfAbsent (p0: K of kotlin.collections.MutableMap?, p1: V of kotlin.collections.MutableMap?): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=T of .Owner.foo? origin=null + $this: GET_VAR 'val map: kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> [val] declared in .Owner.foo' type=kotlin.collections.MutableMap.Owner.foo, T of .Owner.foo> origin=null + p0: GET_VAR 'x: T of .Owner.foo declared in .Owner.foo' type=T of .Owner.foo origin=null + p1: GET_VAR 'y: T of .Owner.foo declared in .Owner.foo' type=T of .Owner.foo 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/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 748bd2354b9..45326ae0400 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1715,6 +1715,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { public void testFirBuilder() throws Exception { runTest("compiler/testData/ir/irText/firProblems/FirBuilder.kt"); } + + @TestMetadata("putIfAbsent.kt") + public void testPutIfAbsent() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/putIfAbsent.kt"); + } } @TestMetadata("compiler/testData/ir/irText/lambdas")