[FIR] Fix signature calculation in JvmMappedScope
This commit is contained in:
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.fir.scopes.jvm
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitAnyTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitNullableAnyTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
||||
@@ -87,12 +89,15 @@ private fun StringBuilder.appendConeType(coneType: ConeKotlinType) {
|
||||
val representative = coneType.lookupTag.typeParameterSymbol.fir.bounds.firstOrNull {
|
||||
(it as? FirResolvedTypeRef)?.type is ConeClassLikeType
|
||||
}
|
||||
if (representative == null) {
|
||||
if (representative == null || representative is FirImplicitNullableAnyTypeRef || representative is FirImplicitAnyTypeRef) {
|
||||
append("Ljava/lang/Object")
|
||||
} else {
|
||||
appendClassLikeType(representative.coneTypeUnsafe())
|
||||
}
|
||||
append(coneType.lookupTag.name)
|
||||
}
|
||||
is ConeFlexibleType -> {
|
||||
appendConeType(coneType.lowerBound)
|
||||
return
|
||||
}
|
||||
}
|
||||
append(";")
|
||||
|
||||
@@ -24,6 +24,8 @@ class JvmMappedScope(
|
||||
?: return declaredMemberScope.processFunctionsByName(name, processor)
|
||||
javaMappedClassUseSiteScope.processFunctionsByName(name) { symbol ->
|
||||
val jvmSignature = symbol.fir.computeJvmDescriptor()
|
||||
.replace("kotlin/Any", "java/lang/Object")
|
||||
.replace("kotlin/String", "java/lang/String")
|
||||
if (jvmSignature in whiteListSignatures) {
|
||||
processor(symbol)
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
|
||||
fun <D> MutableMap<String, MutableSet<D>>.initAndAdd(key: String, value: D) {
|
||||
this.<!UNRESOLVED_REFERENCE!>compute<!>(key) { _, maybeValues ->
|
||||
this.compute(key) { _, maybeValues ->
|
||||
val setOfValues = maybeValues ?: mutableSetOf()
|
||||
setOfValues.<!UNRESOLVED_REFERENCE!>add<!>(value)
|
||||
setOfValues.add(value)
|
||||
setOfValues
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
FILE: MapCompute.kt
|
||||
public final fun <D> R|kotlin/collections/MutableMap<kotlin/String, kotlin/collections/MutableSet<D>>|.initAndAdd(key: R|kotlin/String|, value: R|D|): R|kotlin/Unit| {
|
||||
this@R|/initAndAdd|.<Unresolved name: compute>#(R|<local>/key|, <L> = compute@fun <anonymous>(_: R|ERROR CLASS: No type for parameter|, maybeValues: R|ERROR CLASS: No type for parameter|): R|ERROR CLASS: Unresolved: <error>| {
|
||||
lval setOfValues: R|ERROR CLASS: Unresolved: <error>| = when (lval <elvis>: R|ERROR CLASS: No type for parameter| = R|<local>/maybeValues|) {
|
||||
this@R|/initAndAdd|.R|FakeOverride<java/util/Map.compute: R|kotlin/collections/MutableSet<D>?|>|(R|<local>/key|, <L> = compute@fun <anonymous>(_: R|kotlin/String|, maybeValues: R|kotlin/collections/MutableSet<D>|): R|kotlin/collections/MutableSet<D>| {
|
||||
lval setOfValues: R|kotlin/collections/MutableSet<D>| = when (lval <elvis>: R|kotlin/collections/MutableSet<D>| = R|<local>/maybeValues|) {
|
||||
==($subj$, Null(null)) -> {
|
||||
R|kotlin/collections/mutableSetOf|<R|kotlin/Any?|>()
|
||||
R|kotlin/collections/mutableSetOf|<R|D|>()
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/setOfValues|.<Unresolved name: add>#(R|<local>/value|)
|
||||
R|<local>/setOfValues|.R|FakeOverride<kotlin/collections/MutableSet.add: R|kotlin/Boolean|>|(R|<local>/value|)
|
||||
^ R|<local>/setOfValues|
|
||||
}
|
||||
)
|
||||
|
||||
@@ -12,17 +12,17 @@ class MyException : Exception()
|
||||
fun test(e: MyException, stream: PrintStream) {
|
||||
e.printStackTrace() // Cannot be resolved with early J2K mapping due deriving of kotlin.Throwable instead of java.lang.Throwable
|
||||
e.printStackTrace(stream)
|
||||
val result = e.<!UNRESOLVED_REFERENCE!>getLocalizedMessage<!>()
|
||||
val result = e.getLocalizedMessage()
|
||||
}
|
||||
|
||||
fun test(e: YourException, stream: PrintStream) {
|
||||
e.printStackTrace()
|
||||
e.printStackTrace(stream)
|
||||
val result = e.<!UNRESOLVED_REFERENCE!>getLocalizedMessage<!>()
|
||||
val result = e.getLocalizedMessage()
|
||||
}
|
||||
|
||||
fun test(e: Exception, stream: PrintStream) {
|
||||
e.printStackTrace()
|
||||
e.printStackTrace(stream)
|
||||
val result = e.<!UNRESOLVED_REFERENCE!>getLocalizedMessage<!>()
|
||||
val result = e.getLocalizedMessage()
|
||||
}
|
||||
@@ -7,16 +7,16 @@ FILE: test.kt
|
||||
}
|
||||
public final fun test(e: R|MyException|, stream: R|java/io/PrintStream|): R|kotlin/Unit| {
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|()
|
||||
R|<local>/e|.R|kotlin/printStackTrace|(R|<local>/stream|)
|
||||
lval result: <ERROR TYPE REF: Unresolved name: getLocalizedMessage> = R|<local>/e|.<Unresolved name: getLocalizedMessage>#()
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|(R|<local>/stream|)
|
||||
lval result: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/e|.R|java/lang/Throwable.getLocalizedMessage|()
|
||||
}
|
||||
public final fun test(e: R|YourException|, stream: R|java/io/PrintStream|): R|kotlin/Unit| {
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|()
|
||||
R|<local>/e|.R|kotlin/printStackTrace|(R|<local>/stream|)
|
||||
lval result: <ERROR TYPE REF: Unresolved name: getLocalizedMessage> = R|<local>/e|.<Unresolved name: getLocalizedMessage>#()
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|(R|<local>/stream|)
|
||||
lval result: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/e|.R|java/lang/Throwable.getLocalizedMessage|()
|
||||
}
|
||||
public final fun test(e: R|kotlin/Exception|, stream: R|java/io/PrintStream|): R|kotlin/Unit| {
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|()
|
||||
R|<local>/e|.R|kotlin/printStackTrace|(R|<local>/stream|)
|
||||
lval result: <ERROR TYPE REF: Unresolved name: getLocalizedMessage> = R|<local>/e|.<Unresolved name: getLocalizedMessage>#()
|
||||
R|<local>/e|.R|java/lang/Throwable.printStackTrace|(R|<local>/stream|)
|
||||
lval result: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/e|.R|java/lang/Throwable.getLocalizedMessage|()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ fun test(map: MyMap) {
|
||||
val result = map.getOrPut("key") { "value" } // Cannot be resolved without early J2K mapping
|
||||
// In contrast, should be taken from JDK
|
||||
val otherResult = map.getOrDefault("key", "value")
|
||||
val anotherResult = map.<!UNRESOLVED_REFERENCE!>replace<!>("key", "value")
|
||||
val anotherResult = map.replace("key", "value")
|
||||
// Java forEach
|
||||
map.forEach { key, value ->
|
||||
println("$key: $value")
|
||||
@@ -27,7 +27,7 @@ fun test(map: MutableMap<String, String>) {
|
||||
val result = map.getOrPut("key") { "value" } // Cannot be resolved without early J2K mapping
|
||||
// In contrast, should be taken from JDK
|
||||
val otherResult = map.getOrDefault("key", "value")
|
||||
val anotherResult = map.<!UNRESOLVED_REFERENCE!>replace<!>("key", "value")
|
||||
val anotherResult = map.replace("key", "value")
|
||||
// Java forEach
|
||||
map.forEach { key, value ->
|
||||
println("$key: $value")
|
||||
|
||||
@@ -5,7 +5,7 @@ FILE: test.kt
|
||||
}
|
||||
)
|
||||
lval otherResult: R|ft<kotlin/String, kotlin/String?>!| = R|<local>/map|.R|FakeOverride<kotlin/collections/Map.getOrDefault: R|ft<kotlin/String, kotlin/String?>!|>|(String(key), String(value))
|
||||
lval anotherResult: <ERROR TYPE REF: Unresolved name: replace> = R|<local>/map|.<Unresolved name: replace>#(String(key), String(value))
|
||||
lval anotherResult: R|kotlin/String?| = R|<local>/map|.R|FakeOverride<java/util/Map.replace: R|kotlin/String?|>|(String(key), String(value))
|
||||
R|<local>/map|.R|FakeOverride<java/util/Map.forEach: R|kotlin/Unit|>|(<L> = forEach@fun <anonymous>(key: R|ft<kotlin/String, kotlin/String?>!|, value: R|ft<kotlin/String, kotlin/String?>!|): R|kotlin/Unit| {
|
||||
R|kotlin/io/println|(<strcat>(R|<local>/key|.R|kotlin/Any.toString|(), String(: ), R|<local>/value|.R|kotlin/Any.toString|()))
|
||||
R|<local>/key|.R|kotlin/String.length|
|
||||
@@ -27,7 +27,7 @@ FILE: test.kt
|
||||
}
|
||||
)
|
||||
lval otherResult: R|kotlin/String| = R|<local>/map|.R|FakeOverride<kotlin/collections/Map.getOrDefault: R|kotlin/String|>|(String(key), String(value))
|
||||
lval anotherResult: <ERROR TYPE REF: Unresolved name: replace> = R|<local>/map|.<Unresolved name: replace>#(String(key), String(value))
|
||||
lval anotherResult: R|kotlin/String?| = R|<local>/map|.R|FakeOverride<java/util/Map.replace: R|kotlin/String?|>|(String(key), String(value))
|
||||
R|<local>/map|.R|FakeOverride<java/util/Map.forEach: R|kotlin/Unit|>|(<L> = forEach@fun <anonymous>(key: R|kotlin/String|, value: R|kotlin/String|): R|kotlin/Unit| {
|
||||
R|kotlin/io/println|(<strcat>(R|<local>/key|.R|kotlin/Any.toString|(), String(: ), R|<local>/value|.R|kotlin/Any.toString|()))
|
||||
R|<local>/key|.R|kotlin/String.length|
|
||||
|
||||
@@ -4,12 +4,12 @@ abstract class A : Map<Int, String>
|
||||
|
||||
fun foo(x: Map<Int, String>, a: A, b: java.util.HashMap<Int, String>) {
|
||||
x.getOrDefault(1, "")
|
||||
x.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>("", "")
|
||||
x.getOrDefault("", "")
|
||||
x.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>(1, 2)
|
||||
x.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>("", 2)
|
||||
|
||||
a.getOrDefault(1, "")
|
||||
a.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>("", "")
|
||||
a.getOrDefault("", "")
|
||||
a.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>(1, 2)
|
||||
a.<!INAPPLICABLE_CANDIDATE!>getOrDefault<!>("", 2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user