[FIR] Properly collect overriddens for method enhancement

If some java class has multiple supertypes then we need to collect
  overriddens from all those types directly, even if superTypeScope
  (which is FirTypeIntersectionScope in this case) returns only
  one symbol from one of this types (not intersection one)

This is needed to proper enhancement in cases when some type occurs
  multiple times in supertypes graph with different nullability
  of arguments:

class ConcurrentHashMap<K, V> : AbstractMap<K!, V!>, MutableMap<K, V>

If we try to find method `get(key: K): V` supertype scope returns
  `AbstractMap.get(key: K!): V!` (because it actually overrides
  `MutableMap(key: K): V?`), but we need to get both symbols to
  properly enhance types for `ConcurrentHashMap.remove`
This commit is contained in:
Dmitriy Novozhilov
2021-11-19 18:16:07 +03:00
parent 01c0cf80d0
commit 9807c67ae4
42 changed files with 393 additions and 301 deletions
@@ -0,0 +1,29 @@
// FULL_JDK
// FILE: Util.java
public class Util {
public static String getString() { return null; }
}
// FILE: main.kt
import java.util.concurrent.ConcurrentHashMap
fun testWithMap(map: ConcurrentHashMap<Int, String>): Int {
var string = map[1]
if (string == null) {
string = map.computeIfAbsent(1) { "hello" }
}
return string.length
}
fun testWithUtil(map: ConcurrentHashMap<Int, String>): Int {
var string = map[1]
if (string == null) {
string = Util.getString()
}
return string<!UNSAFE_CALL!>.<!>length
}
fun test(list: java.util.ArrayList<String?>) {
val x = list.get(0)<!UNSAFE_CALL!>.<!>length
}
@@ -0,0 +1,29 @@
// FULL_JDK
// FILE: Util.java
public class Util {
public static String getString() { return null; }
}
// FILE: main.kt
import java.util.concurrent.ConcurrentHashMap
fun testWithMap(map: ConcurrentHashMap<Int, String>): Int {
var string = map[1]
if (string == null) {
string = map.computeIfAbsent(1) { "hello" }
}
return <!DEBUG_INFO_SMARTCAST!>string<!>.length
}
fun testWithUtil(map: ConcurrentHashMap<Int, String>): Int {
var string = map[1]
if (string == null) {
string = Util.getString()
}
return string<!UNSAFE_CALL!>.<!>length
}
fun test(list: java.util.ArrayList<String?>) {
val x = list.get(0)<!UNSAFE_CALL!>.<!>length
}
@@ -0,0 +1,15 @@
package
public fun test(/*0*/ list: java.util.ArrayList<kotlin.String?>): kotlin.Unit
public fun testWithMap(/*0*/ map: java.util.concurrent.ConcurrentHashMap<kotlin.Int, kotlin.String>): kotlin.Int
public fun testWithUtil(/*0*/ map: java.util.concurrent.ConcurrentHashMap<kotlin.Int, kotlin.String>): kotlin.Int
public open class Util {
public constructor Util()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public open fun getString(): kotlin.String!
}