K2: fix outerClassSymbol behavior for local classes #KT-55018 Fixed
This commit is contained in:
committed by
Space Team
parent
fb09f139dd
commit
1d76bce3dd
@@ -116,8 +116,7 @@ fun FirBasedSymbol<*>.getContainingClassSymbol(session: FirSession): FirClassLik
|
|||||||
|
|
||||||
fun FirClassLikeSymbol<*>.outerClassSymbol(context: CheckerContext): FirClassLikeSymbol<*>? {
|
fun FirClassLikeSymbol<*>.outerClassSymbol(context: CheckerContext): FirClassLikeSymbol<*>? {
|
||||||
if (this !is FirClassSymbol<*>) return null
|
if (this !is FirClassSymbol<*>) return null
|
||||||
val outerClassId = classId.outerClassId ?: return null
|
return getContainingDeclarationSymbol(context.session)
|
||||||
return context.session.symbolProvider.getClassLikeSymbolByClassId(outerClassId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(SymbolInternals::class)
|
@OptIn(SymbolInternals::class)
|
||||||
|
|||||||
+1
-1
@@ -192,7 +192,7 @@ object FirOptInUsageBaseChecker {
|
|||||||
context, result, visited, fromSetter = false, dispatchReceiverType, fromSupertype = false
|
context, result, visited, fromSetter = false, dispatchReceiverType, fromSupertype = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (this is FirRegularClassSymbol && fir is FirRegularClass && !fir.isLocal) {
|
} else if (this is FirRegularClassSymbol && fir is FirRegularClass) {
|
||||||
val parentClassSymbol = outerClassSymbol(context)
|
val parentClassSymbol = outerClassSymbol(context)
|
||||||
parentClassSymbol?.loadExperimentalities(
|
parentClassSymbol?.loadExperimentalities(
|
||||||
context, result, visited, fromSetter = false, dispatchReceiverType = null, fromSupertype = false
|
context, result, visited, fromSetter = false, dispatchReceiverType = null, fromSupertype = false
|
||||||
|
|||||||
Generated
+6
@@ -2666,6 +2666,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localCompanion.kt")
|
||||||
|
public void testLocalCompanion() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/localCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("Modality.kt")
|
@TestMetadata("Modality.kt")
|
||||||
public void testModality() throws Exception {
|
public void testModality() throws Exception {
|
||||||
|
|||||||
+6
@@ -2666,6 +2666,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localCompanion.kt")
|
||||||
|
public void testLocalCompanion() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/localCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("Modality.kt")
|
@TestMetadata("Modality.kt")
|
||||||
public void testModality() throws Exception {
|
public void testModality() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
FILE fqName:<root> fileName:/localCompanion.kt
|
||||||
|
FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
|
BLOCK_BODY
|
||||||
|
CLASS CLASS name:Foo modality:FINAL visibility:local superTypes:[kotlin.Any]
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.main.Foo
|
||||||
|
CONSTRUCTOR visibility:public <> () returnType:<root>.main.Foo [primary]
|
||||||
|
BLOCK_BODY
|
||||||
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||||
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:local superTypes:[kotlin.Any]'
|
||||||
|
CLASS OBJECT name:Companion modality:FINAL visibility:local [companion] superTypes:[kotlin.Any]
|
||||||
|
annotations:
|
||||||
|
Suppress(names = ['WRONG_MODIFIER_CONTAINING_DECLARATION'])
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.main.Foo.Companion
|
||||||
|
CONSTRUCTOR visibility:private <> () returnType:<root>.main.Foo.Companion [primary]
|
||||||
|
BLOCK_BODY
|
||||||
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||||
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Companion modality:FINAL visibility:local [companion] superTypes:[kotlin.Any]'
|
||||||
|
FUN name:bar visibility:public modality:FINAL <> ($this:<root>.main.Foo.Companion) returnType:kotlin.Unit
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:<root>.main.Foo.Companion
|
||||||
|
BLOCK_BODY
|
||||||
|
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 [operator] declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||||
|
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||||
|
overridden:
|
||||||
|
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||||
|
overridden:
|
||||||
|
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
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 [operator] declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||||
|
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||||
|
overridden:
|
||||||
|
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||||
|
overridden:
|
||||||
|
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
|
CALL 'public final fun bar (): kotlin.Unit declared in <root>.main.Foo.Companion' type=kotlin.Unit origin=null
|
||||||
|
$this: GET_OBJECT 'CLASS OBJECT name:Companion modality:FINAL visibility:local [companion] superTypes:[kotlin.Any]' type=<root>.main.Foo.Companion
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
fun main() {
|
||||||
|
class Foo {
|
||||||
|
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
|
||||||
|
companion object {
|
||||||
|
fun bar() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Foo.Companion.bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
fun main() {
|
||||||
|
local class Foo {
|
||||||
|
constructor() /* primary */ {
|
||||||
|
super/*Any*/()
|
||||||
|
/* <init>() */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress(names = ["WRONG_MODIFIER_CONTAINING_DECLARATION"])
|
||||||
|
local companion object Companion {
|
||||||
|
private constructor() /* primary */ {
|
||||||
|
super/*Any*/()
|
||||||
|
/* <init>() */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Companion.bar()
|
||||||
|
}
|
||||||
Generated
+6
@@ -2666,6 +2666,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("localCompanion.kt")
|
||||||
|
public void testLocalCompanion() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/localCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("Modality.kt")
|
@TestMetadata("Modality.kt")
|
||||||
public void testModality() throws Exception {
|
public void testModality() throws Exception {
|
||||||
|
|||||||
@@ -1950,6 +1950,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
runTest("compiler/testData/ir/irText/firProblems/localClassUsedBeforeDeclaration.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localCompanion.kt")
|
||||||
|
public void testLocalCompanion() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/localCompanion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("readWriteProperty.kt")
|
@TestMetadata("readWriteProperty.kt")
|
||||||
public void testReadWriteProperty() throws Exception {
|
public void testReadWriteProperty() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/firProblems/readWriteProperty.kt");
|
runTest("compiler/testData/ir/irText/firProblems/readWriteProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user