FIR: make override resolve in use-site session (and module)
Related to KT-24078
This commit is contained in:
+15
-8
@@ -12,11 +12,16 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirTopLevelDeclaredMemberScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirTopLevelDeclaredMemberScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.types.impl.ConeAbbreviatedTypeImpl
|
||||||
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
import org.jetbrains.kotlin.fir.visitors.compose
|
import org.jetbrains.kotlin.fir.visitors.compose
|
||||||
|
|
||||||
@@ -31,15 +36,17 @@ class FirAccessResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(rev
|
|||||||
|
|
||||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||||
return withScopeCleanup {
|
return withScopeCleanup {
|
||||||
lookupSuperTypes(regularClass).asReversed().mapNotNullTo(towerScope.scopes) {
|
val useSiteSession = regularClass.session
|
||||||
val symbol = it.symbol
|
lookupSuperTypes(regularClass).asReversed()
|
||||||
if (symbol is FirClassSymbol) {
|
.mapNotNullTo(towerScope.scopes) { useSiteSuperType ->
|
||||||
FirClassDeclaredMemberScope(symbol.fir, symbol.fir.session)
|
val symbol = useSiteSuperType.symbol
|
||||||
} else {
|
if (symbol is FirClassSymbol) {
|
||||||
null
|
FirClassDeclaredMemberScope(symbol.fir, useSiteSession)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
towerScope.scopes += FirClassDeclaredMemberScope(regularClass, useSiteSession)
|
||||||
towerScope.scopes += FirClassDeclaredMemberScope(regularClass, regularClass.session)
|
|
||||||
super.transformRegularClass(regularClass, data)
|
super.transformRegularClass(regularClass, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
expect class MyList {
|
||||||
|
fun get(i: Int): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
open class Wrapper(val list: MyList)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
FILE: common.kt
|
||||||
|
public final expect class MyList {
|
||||||
|
public constructor(): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
|
public final function get(i: R|kotlin/Int|): R|kotlin/Int|
|
||||||
|
|
||||||
|
}
|
||||||
|
public open class Wrapper {
|
||||||
|
public constructor(list: R|MyList|): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
|
public final property list(val): R|MyList|
|
||||||
|
public get(): R|MyList|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
actual class MyList {
|
||||||
|
actual fun get(i: Int): Int = i
|
||||||
|
|
||||||
|
fun set(i: Int, v: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DerivedList : MyList() {
|
||||||
|
fun useMember() {
|
||||||
|
get(1)
|
||||||
|
set(2, 3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun useList(list: MyList) {
|
||||||
|
// We should deal with receiver to resolve this
|
||||||
|
list.get(1)
|
||||||
|
list.set(2, 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
class DerivedWrapper : Wrapper() {
|
||||||
|
fun use() {
|
||||||
|
// We should deal with receiver to resolve this
|
||||||
|
list.get(1)
|
||||||
|
list.set(2, 3)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
FILE: jvm.kt
|
||||||
|
public final actual class MyList {
|
||||||
|
public constructor(): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
|
public final actual function get(i: R|kotlin/Int|): R|kotlin/Int| {
|
||||||
|
return@@@get <Unresolved name: i>#
|
||||||
|
}
|
||||||
|
|
||||||
|
public final function set(i: R|kotlin/Int|, v: R|kotlin/Int|): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final class DerivedList : R|MyList| {
|
||||||
|
public constructor(): super<R|MyList|>()
|
||||||
|
|
||||||
|
public final function useMember(): R|kotlin/Unit| {
|
||||||
|
R|/MyList.get|(Int(1))
|
||||||
|
R|/MyList.set|(Int(2), Int(3))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final function useList(list: R|MyList|): R|kotlin/Unit| {
|
||||||
|
<Unresolved name: list>#.<Unresolved name: get>#(Int(1))
|
||||||
|
<Unresolved name: list>#.<Unresolved name: set>#(Int(2), Int(3))
|
||||||
|
}
|
||||||
|
public final class DerivedWrapper : R|Wrapper| {
|
||||||
|
public constructor(): super<R|Wrapper|>()
|
||||||
|
|
||||||
|
public final function use(): R|kotlin/Unit| {
|
||||||
|
<Unresolved name: list>#.<Unresolved name: get>#(Int(1))
|
||||||
|
<Unresolved name: list>#.<Unresolved name: set>#(Int(2), Int(3))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@ FILE: jvm.kt
|
|||||||
|
|
||||||
public final function test(): R|kotlin/Unit| {
|
public final function test(): R|kotlin/Unit| {
|
||||||
R|/A.foo|()
|
R|/A.foo|()
|
||||||
<Unresolved name: bar>#()
|
R|/A.bar|()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
expect open class A() {
|
||||||
|
fun foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class B : A()
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
FILE: common.kt
|
||||||
|
public open expect class A {
|
||||||
|
public constructor(): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
|
public final function foo(): R|kotlin/Unit|
|
||||||
|
|
||||||
|
}
|
||||||
|
public open class B : R|A| {
|
||||||
|
public constructor(): super<R|A|>()
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
abstract class X {
|
||||||
|
fun bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Y {
|
||||||
|
fun baz() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual open class A : X(), Y {
|
||||||
|
actual fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : B() {
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
// This cannot be resolved yet due to lack of search symbols / projections
|
||||||
|
bar()
|
||||||
|
// This cannot be resolved yet due to lack of interface lookup
|
||||||
|
baz()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : A() {
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
bar()
|
||||||
|
// This cannot be resolved yet due to lack of interface lookup
|
||||||
|
baz()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
FILE: jvm.kt
|
||||||
|
public abstract class X {
|
||||||
|
public constructor(): super<R|kotlin/Any|>()
|
||||||
|
|
||||||
|
public final function bar(): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public abstract interface Y {
|
||||||
|
public open function baz(): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public open actual class A : R|X|, R|Y| {
|
||||||
|
public constructor(): super<R|X|>()
|
||||||
|
|
||||||
|
public final actual function foo(): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final class C : R|B| {
|
||||||
|
public constructor(): super<R|B|>()
|
||||||
|
|
||||||
|
public final function test(): R|kotlin/Unit| {
|
||||||
|
R|/A.foo|()
|
||||||
|
<Unresolved name: bar>#()
|
||||||
|
<Unresolved name: baz>#()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final class D : R|A| {
|
||||||
|
public constructor(): super<R|A|>()
|
||||||
|
|
||||||
|
public final function test(): R|kotlin/Unit| {
|
||||||
|
R|/A.foo|()
|
||||||
|
R|/X.bar|()
|
||||||
|
<Unresolved name: baz>#()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
@@ -34,8 +34,18 @@ public class FirMultiModuleResolveTestGenerated extends AbstractFirMultiModuleRe
|
|||||||
runTest("idea/testData/fir/multiModule/basic/");
|
runTest("idea/testData/fir/multiModule/basic/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mppMemberType")
|
||||||
|
public void testMppMemberType() throws Exception {
|
||||||
|
runTest("idea/testData/fir/multiModule/mppMemberType/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("mppMembers")
|
@TestMetadata("mppMembers")
|
||||||
public void testMppMembers() throws Exception {
|
public void testMppMembers() throws Exception {
|
||||||
runTest("idea/testData/fir/multiModule/mppMembers/");
|
runTest("idea/testData/fir/multiModule/mppMembers/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("mppSuperTypes")
|
||||||
|
public void testMppSuperTypes() throws Exception {
|
||||||
|
runTest("idea/testData/fir/multiModule/mppSuperTypes/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user