IR: fix "most specific" check in IrFakeOverrideBuilder

There were several problems with it:

1) `isMoreSpecific` should return true if a == b. Otherwise
   `isMoreSpecificThenAllOf` would never return true because it's always
   invoked with a collection that contains the candidate. K1 behaves
   similarly, `OverridingUtil.isMoreSpecific` returns true if a == b.
   So in fact, "more" should be understood as "not less" here.
2) `transitivelyMostSpecificMember` in `selectMostSpecificMember` was
   always equal to the first element, so `isMoreSpecific` was invoked
   with incorrect arguments.
3) At the end of `selectMostSpecificMember`, we selected the first
   candidate with the non-flexible return type, however only dynamic
   type was considered. We need to check `isFlexible` via type system
   instead.

 #KT-66120 Fixed
This commit is contained in:
Alexander Udalov
2024-03-01 14:13:04 +01:00
committed by Space Team
parent a08df1821f
commit 77b3f415a5
17 changed files with 32 additions and 2761 deletions
@@ -295,14 +295,14 @@ FILE fqName:<root> fileName:/1.kt
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Java1'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:H modality:FINAL visibility:public superTypes:[<root>.Java1; <root>.Java2; <root>.Java3]'
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java3) returnType:@[EnhancedNullability] kotlin.String? [fake_override]
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java2) returnType:@[EnhancedNullability] kotlin.String [fake_override]
annotations:
Nullable(value = <null>)
NotNull(value = <null>)
overridden:
public open fun bar (): @[FlexibleNullability] kotlin.String? declared in <root>.Java1
public abstract fun bar (): @[EnhancedNullability] kotlin.String declared in <root>.Java2
public abstract fun bar (): @[EnhancedNullability] kotlin.String? declared in <root>.Java3
$this: VALUE_PARAMETER name:<this> type:<root>.Java3
$this: VALUE_PARAMETER name:<this> type:<root>.Java2
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 declared in <root>.Java1
@@ -488,7 +488,7 @@ FILE fqName:<root> fileName:/1.kt
receiver: GET_VAR 'h: <root>.H declared in <root>.test' type=<root>.H origin=null
VAR name:k16 type:kotlin.String [val]
TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
CALL 'public open fun bar (): @[EnhancedNullability] kotlin.String? declared in <root>.H' type=@[EnhancedNullability] kotlin.String origin=null
CALL 'public open fun bar (): @[EnhancedNullability] kotlin.String declared in <root>.H' type=@[EnhancedNullability] kotlin.String origin=null
$this: GET_VAR 'h: <root>.H declared in <root>.test' type=<root>.H origin=null
CALL 'public open fun foo (s: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in <root>.H' type=kotlin.Unit origin=null
$this: GET_VAR 'h: <root>.H declared in <root>.test' type=<root>.H origin=null
@@ -210,10 +210,10 @@ class H : Java1, Java2, Java3 {
constructor() /* primary */
// CHECK JVM_IR:
// Mangled name: H#bar(){}kotlin.String?{EnhancedNullability}
// Public signature: /H.bar|7290041286951472444[0]
// Public signature debug description: bar(){}kotlin.String?{EnhancedNullability}
/* fake */ override fun bar(): @EnhancedNullability String?
// Mangled name: H#bar(){}kotlin.String{EnhancedNullability}
// Public signature: /H.bar|-4383985778696477509[0]
// Public signature debug description: bar(){}kotlin.String{EnhancedNullability}
/* fake */ override fun bar(): @EnhancedNullability String
// CHECK:
// Mangled name: H#foo(kotlin.String?){}
@@ -286,3 +286,4 @@ interface KotlinInterface2 {
// Public signature: /test|-2663909601123444132[0]
// Public signature debug description: test(A;B;C;D;E;F;G;H){}
fun test(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): Unit