K2: prefer derived class sources for callable copies (e.g. fake overrides)

This commit is contained in:
Mikhail Glukhikh
2023-10-19 14:28:54 +02:00
committed by Space Team
parent 4b2a122f80
commit 3cb9396b20
27 changed files with 141 additions and 54 deletions
@@ -130,6 +130,12 @@ public class FirLightTreeJvmIrSourceRangesTestGenerated extends AbstractFirLight
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides.kt");
}
@Test
@TestMetadata("fakeOverrides2.kt")
public void testFakeOverrides2() throws Exception {
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides2.kt");
}
@Test
@TestMetadata("kt29862.kt")
public void testKt29862() throws Exception {
@@ -130,6 +130,12 @@ public class FirPsiJvmIrSourceRangesTestGenerated extends AbstractFirPsiJvmIrSou
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides.kt");
}
@Test
@TestMetadata("fakeOverrides2.kt")
public void testFakeOverrides2() throws Exception {
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides2.kt");
}
@Test
@TestMetadata("kt29862.kt")
public void testKt29862() throws Exception {
@@ -122,7 +122,7 @@ object FirFakeOverrideGenerator {
checkStatusIsResolved(baseFunction)
return buildSimpleFunction {
source = baseFunction.source ?: derivedClassLookupTag?.toSymbol(session)?.source
source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseFunction.source
moduleData = session.nullableModuleData ?: baseFunction.moduleData
this.origin = origin
name = baseFunction.name
@@ -162,7 +162,7 @@ object FirFakeOverrideGenerator {
// As second alternative, we can invent some light-weight kind of FirRegularClass
return buildConstructor {
annotations += baseConstructor.annotations
source = baseConstructor.source ?: derivedClassLookupTag?.toSymbol(session)?.source
source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseConstructor.source
moduleData = session.nullableModuleData ?: baseConstructor.moduleData
this.origin = origin
receiverParameter = baseConstructor.receiverParameter?.let { receiverParameter ->
@@ -302,7 +302,7 @@ object FirFakeOverrideGenerator {
) { valueParameter, newType ->
buildValueParameterCopy(valueParameter) {
this.origin = origin
source = source ?: this@configureAnnotationsAndSignature.source
source = this@configureAnnotationsAndSignature.source ?: source
returnTypeRef = valueParameter.returnTypeRef.withReplacedConeType(newType)
symbol = FirValueParameterSymbol(valueParameter.name)
containingFunctionSymbol = fakeFunctionSymbol
@@ -371,7 +371,7 @@ object FirFakeOverrideGenerator {
checkStatusIsResolved(baseProperty)
return buildProperty {
source = baseProperty.source ?: derivedClassLookupTag?.toSymbol(session)?.source
source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseProperty.source
moduleData = session.nullableModuleData ?: baseProperty.moduleData
this.origin = origin
name = baseProperty.name
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun <T> foo(t: T) {}<!>
open fun <T> foo(t: T) {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,12 +2,12 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open var red1: String = ""<!>
<!INCOMPATIBLE_MATCHING{JVM}!>open lateinit var red2: String<!>
open var red1: String = ""
open lateinit var red2: String
open lateinit var green: String
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
}<!>
// MODULE: m2-jvm()()(m1-common)
@@ -2,10 +2,10 @@
// FILE: common.kt
interface Base {
<!INCOMPATIBLE_MATCHING{JVM}!>fun foo()<!>
fun foo()
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Foo<!> : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Foo<!> : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -1,9 +1,9 @@
// MODULE: m1-common
// FILE: common.kt
interface Base {
<!INCOMPATIBLE_MATCHING{JVM}!>fun foo()<!>
fun foo()
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Foo<!>() : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Foo<!>() : Base<!>
// MODULE: m2-jvm()()(m1-common)
@@ -1,9 +1,9 @@
// MODULE: m1-common
// FILE: common.kt
interface Base {
<!INCOMPATIBLE_MATCHING{JVM}!>fun foo() {}<!>
fun foo() {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect abstract class Foo() : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect abstract class Foo() : Base<!>
// MODULE: m2-jvm()()(m1-common)
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo() {}<!>
open fun foo() {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base<T> {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(t: T) {}<!>
open fun foo(t: T) {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<String><!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<String><!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(param: Int) {}<!>
open fun foo(param: Int) {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo1 : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo1 : Base<!>
expect open class Foo2 : Base
expect open class Foo3 {
open fun foo(param: Int)
@@ -2,11 +2,11 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open var foo: String = ""
protected set<!>
open var foo: String = ""
protected set
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(vararg bar: Int) {}<!>
open fun foo(vararg bar: Int) {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
}<!>
// MODULE: m2-jvm()()(m1-common)
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>protected open fun foo() {}<!>
protected open fun foo() {}
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -3,10 +3,10 @@
open class Base {
open val foo: String = ""
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>open fun foo(): Any = ""<!>
open fun foo(): Any = ""
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
}<!>
// MODULE: m2-jvm()()(m1-common)
@@ -4,10 +4,10 @@
interface I
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(): I = null!!<!>
open fun foo(): I = null!!
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo<T : I> : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo<T : I> : Base {
}<!>
// MODULE: m2-jvm()()(m1-common)
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base<R> {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(): R = null!!<!>
open fun foo(): R = null!!
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo<R, T : R> : Base<R> {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo<R, T : R> : Base<R> {
}<!>
// MODULE: m2-jvm()()(m1-common)
@@ -2,11 +2,11 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>open val foo: Any = ""<!>
open val foo: Any = ""
open fun foo(): String = ""
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,10 +2,10 @@
// FILE: common.kt
expect open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun foo(): MutableList<String><!>
open fun foo(): MutableList<String>
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
}<!>
@@ -2,10 +2,10 @@
// FILE: common.kt
open class Base {
<!INCOMPATIBLE_MATCHING{JVM}!>open val foo: Int = 1<!>
open val foo: Int = 1
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
@@ -2,13 +2,13 @@
// FILE: common.kt
open class Base() {
<!INCOMPATIBLE_MATCHING{JVM}!>open fun overrideReturnType(): Any = ""<!>
<!INCOMPATIBLE_MATCHING{JVM}!>open fun overrideModality1(): Any = ""<!>
<!INCOMPATIBLE_MATCHING{JVM}!>open fun overrideModality2(): Any = ""<!>
<!INCOMPATIBLE_MATCHING{JVM}!>protected open fun overrideVisibility(): Any = ""<!>
open fun overrideReturnType(): Any = ""
open fun overrideModality1(): Any = ""
open fun overrideModality2(): Any = ""
protected open fun overrideVisibility(): Any = ""
}
<!INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
<!INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}, INCOMPATIBLE_MATCHING{JVM}!>expect open class Foo : Base {
fun existingMethod()
val existingParam: Int
}<!>
@@ -1,9 +0,0 @@
interface B {
fun getX() = 1
}
interface D {
<!ACCIDENTAL_OVERRIDE!>val x: Int<!>
}
class C(d: D) : D by d, B
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface B {
fun getX() = 1
}
@@ -0,0 +1,35 @@
@0:0..7:0 FILE fqName:<root> fileName:/fakeOverrides2.kt
@0:0..2:1 CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
@0:17..18 TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
@0:0..2:1 CONSTRUCTOR visibility:public <> () returnType:<root>.A<T of <root>.A> [primary]
@0:0..2:1 BLOCK_BODY
@0:0..2:1 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@0:0..2:1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]'
@1:4..27 FUN name:foo visibility:public modality:FINAL <> ($this:<root>.A<T of <root>.A>, x:T of <root>.A) returnType:kotlin.Unit
@1:4..27 VALUE_PARAMETER name:<this> type:<root>.A<T of <root>.A>
@1:12..16 VALUE_PARAMETER name:x index:0 type:T of <root>.A
@1:18..20 BLOCK_BODY
@0:0..2:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:0..2:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any?
@0:0..2:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:0..2:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:0..2:1 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A<T of <root>.A>
@4:0..6:1 CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A<kotlin.String>]
@4:0..6:1 CONSTRUCTOR visibility:public <> () returnType:<root>.B [primary]
@4:0..6:1 BLOCK_BODY
@4:10..21 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.A'
@4:0..6:1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A<kotlin.String>]'
@4:0..6:1 FUN FAKE_OVERRIDE name:foo visibility:public modality:FINAL <> ($this:<root>.A<kotlin.String>, x:kotlin.String) returnType:kotlin.Unit [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:<root>.A<kotlin.String>
@4:0..6:1 VALUE_PARAMETER name:x index:0 type:kotlin.String
@4:0..6:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any?
@4:0..6:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
@@ -0,0 +1,7 @@
abstract class A<T> {
fun foo(x: T) {} // (1)
}
class B : A<String>() {
// fake-override fun foo(x: String) // (2) should use 'B' class source
}
@@ -0,0 +1,35 @@
@0:0..7:0 FILE fqName:<root> fileName:/fakeOverrides2.kt
@0:0..2:1 CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
@0:17..18 TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
@0:9..2:1 CONSTRUCTOR visibility:public <> () returnType:<root>.A<T of <root>.A> [primary]
@0:0..2:1 BLOCK_BODY
@0:0..2:1 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
@0:0..2:1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]'
@1:4..27 FUN name:foo visibility:public modality:FINAL <> ($this:<root>.A<T of <root>.A>, x:T of <root>.A) returnType:kotlin.Unit
@1:4..27 VALUE_PARAMETER name:<this> type:<root>.A<T of <root>.A>
@1:12..16 VALUE_PARAMETER name:x index:0 type:T of <root>.A
@1:18..20 BLOCK_BODY
@0:9..2:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:9..2:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any?
@0:9..2:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:9..2:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
@0:0..2:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@0:0..2:1 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A<T of <root>.A>
@4:0..6:1 CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A<kotlin.String>]
@4:0..6:1 CONSTRUCTOR visibility:public <> () returnType:<root>.B [primary]
@4:0..6:1 BLOCK_BODY
@4:10..21 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.A'
@4:0..6:1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[<root>.A<kotlin.String>]'
@4:0..6:1 FUN FAKE_OVERRIDE name:foo visibility:public modality:FINAL <> ($this:<root>.A<kotlin.String>, x:kotlin.String) returnType:kotlin.Unit [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:<root>.A<kotlin.String>
@4:0..6:1 VALUE_PARAMETER name:x index:0 type:kotlin.String
@4:0..6:1 FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 VALUE_PARAMETER name:other index:0 type:kotlin.Any?
@4:0..6:1 FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
@4:0..6:1 VALUE_PARAMETER name:<this> type:kotlin.Any
@4:0..6:1 VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
@@ -130,6 +130,12 @@ public class ClassicJvmIrSourceRangesTestGenerated extends AbstractClassicJvmIrS
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides.kt");
}
@Test
@TestMetadata("fakeOverrides2.kt")
public void testFakeOverrides2() throws Exception {
runTest("compiler/testData/ir/sourceRanges/declarations/fakeOverrides2.kt");
}
@Test
@TestMetadata("kt29862.kt")
public void testKt29862() throws Exception {