[LT2FIR] Fix missing "expect" modifier on members of nested classes

For members of nested classes inside expect class
`classWrapper.hasExpect()` would be false, because it only reflects
modifiers of nested class itself and not aware of "expect" modifier
inherited from the parent class.
Fix is done in same way in PSI2FIR, see
`PsiRawFirBuilder.Visitor.toFirProperty`.

This fix now makes it possible to add test for functionality from
previous commit.

Review: KT-MR-12107

^KT-61784
This commit is contained in:
Roman Efremov
2023-09-08 16:44:25 +02:00
committed by Space Team
parent c6d7f15070
commit 2dae7ce6c1
22 changed files with 268 additions and 4 deletions
@@ -153,6 +153,24 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@Test
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@Test
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@Test
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@Test
@TestMetadata("external.kt")
public void testExternal() throws Exception {
@@ -153,6 +153,24 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@Test
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@Test
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@Test
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@Test
@TestMetadata("external.kt")
public void testExternal() throws Exception {
@@ -1036,6 +1036,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/methodDefaultArgsViaActualTypealias_oldLanguageVersion.kt");
}
@Test
@TestMetadata("nestedAnnotationClassViaActualTypealias.kt")
public void testNestedAnnotationClassViaActualTypealias() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/nestedAnnotationClassViaActualTypealias.kt");
}
@Test
@TestMetadata("nestedClassMethodsViaActualTypealias.kt")
public void testNestedClassMethodsViaActualTypealias() throws Exception {
@@ -1036,6 +1036,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/methodDefaultArgsViaActualTypealias_oldLanguageVersion.kt");
}
@Test
@TestMetadata("nestedAnnotationClassViaActualTypealias.kt")
public void testNestedAnnotationClassViaActualTypealias() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/nestedAnnotationClassViaActualTypealias.kt");
}
@Test
@TestMetadata("nestedClassMethodsViaActualTypealias.kt")
public void testNestedClassMethodsViaActualTypealias() throws Exception {
@@ -572,7 +572,7 @@ class LightTreeRawFirDeclarationBuilder(
it.toFirPropertyFromPrimaryConstructor(
baseModuleData,
callableIdForName(it.firValueParameter.name),
classWrapper.hasExpect(),
classIsExpect,
currentDispatchReceiverType(),
context
)
@@ -611,19 +611,19 @@ class LightTreeRawFirDeclarationBuilder(
baseModuleData,
context.packageFqName,
context.className,
modifiers.hasExpect()
classIsExpect
)
generateValueOfFunction(
baseModuleData,
context.packageFqName,
context.className,
modifiers.hasExpect()
classIsExpect
)
generateEntriesGetter(
baseModuleData,
context.packageFqName,
context.className,
modifiers.hasExpect()
classIsExpect
)
}
initCompanionObjectSymbolAttr()
@@ -141,6 +141,21 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@TestMetadata("external.kt")
public void testExternal() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt");
@@ -0,0 +1,3 @@
expect class Outer {
annotation class AnnotationNested(val p: String = "")
}
@@ -0,0 +1,11 @@
FILE: expectNestedAnnotationClassWithConstructorParameter.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect annotation class AnnotationNested : R|kotlin/Annotation| {
public? expect constructor(p: String = LAZY_EXPRESSION): R|Outer.AnnotationNested|
public? final? expect val p: String = R|<local>/p|
public? get(): String
}
}
@@ -0,0 +1,11 @@
FILE: expectNestedAnnotationClassWithConstructorParameter.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect annotation class AnnotationNested : R|kotlin/Annotation| {
public? expect [ContainingClassKey=AnnotationNested] constructor([CorrespondingProperty=/Outer.AnnotationNested.p] p: String = String()): R|Outer.AnnotationNested|
public? final? expect [IsFromPrimaryConstructor=true] val p: String = R|<local>/p|
public? [ContainingClassKey=AnnotationNested] get(): String
}
}
@@ -0,0 +1,7 @@
expect class Outer {
class Nested {
fun function()
var property: Any
}
}
@@ -0,0 +1,12 @@
FILE: expectNestedClassMembers.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect class Nested : R|kotlin/Any| {
public? final? expect fun function(): R|kotlin/Unit|
public? final? expect var property: Any
public? get(): Any
public? set(value: Any): R|kotlin/Unit|
}
}
@@ -0,0 +1,12 @@
FILE: expectNestedClassMembers.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect class Nested : R|kotlin/Any| {
public? final? expect fun function(): R|kotlin/Unit|
public? final? expect var property: Any
public? [ContainingClassKey=Nested] get(): Any
public? [ContainingClassKey=Nested] set(value: Any): R|kotlin/Unit|
}
}
@@ -0,0 +1,5 @@
expect class Outer {
enum class NestedEnum {
ONE, TWO
}
}
@@ -0,0 +1,19 @@
FILE: expectNestedEnumClassGeneratedMembers.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect enum class NestedEnum : R|kotlin/Enum<Outer.NestedEnum>| {
private expect constructor(): R|Outer.NestedEnum|
public final expect static enum entry ONE: R|Outer.NestedEnum|
public final expect static enum entry TWO: R|Outer.NestedEnum|
public final expect static fun values(): R|kotlin/Array<Outer.NestedEnum>| {
}
public final expect static fun valueOf(value: R|kotlin/String|): R|Outer.NestedEnum| {
}
public final expect static val entries: R|kotlin/enums/EnumEntries<Outer.NestedEnum>|
public get(): R|kotlin/enums/EnumEntries<Outer.NestedEnum>|
}
}
@@ -0,0 +1,19 @@
FILE: expectNestedEnumClassGeneratedMembers.kt
public? final? expect class Outer : R|kotlin/Any| {
public? final? expect enum class NestedEnum : R|kotlin/Enum<Outer.NestedEnum>| {
private expect [ContainingClassKey=NestedEnum] constructor(): R|Outer.NestedEnum|
public final expect static [ContainingClassKey=NestedEnum] enum entry ONE: R|Outer.NestedEnum|
public final expect static [ContainingClassKey=NestedEnum] enum entry TWO: R|Outer.NestedEnum|
public final expect static [ContainingClassKey=NestedEnum] fun values(): R|kotlin/Array<Outer.NestedEnum>| {
}
public final expect static [ContainingClassKey=NestedEnum] fun valueOf(value: R|kotlin/String|): R|Outer.NestedEnum| {
}
public final expect static [ContainingClassKey=NestedEnum] val entries: R|kotlin/enums/EnumEntries<Outer.NestedEnum>|
public get(): R|kotlin/enums/EnumEntries<Outer.NestedEnum>|
}
}
@@ -141,6 +141,21 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@TestMetadata("external.kt")
public void testExternal() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt");
@@ -141,6 +141,21 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@TestMetadata("external.kt")
public void testExternal() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/external.kt");
@@ -0,0 +1,15 @@
// TODO: test fails, fix in subsequent commits
// MODULE: m1-common
// FILE: common.kt
<!INCOMPATIBLE_MATCHING{JVM}!>expect class DefaultArgsInNestedClass {
<!INCOMPATIBLE_MATCHING{JVM}!>annotation class Nested<!INCOMPATIBLE_MATCHING{JVM}!>(val p: String = "")<!><!>
}<!>
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
class DefaultArgsInNestedClassImpl {
annotation class Nested(val p: String = "")
}
// Incompatible because of bug KT-31636
actual typealias DefaultArgsInNestedClass = DefaultArgsInNestedClassImpl
@@ -0,0 +1,15 @@
// TODO: test fails, fix in subsequent commits
// MODULE: m1-common
// FILE: common.kt
expect class DefaultArgsInNestedClass {
annotation class Nested(val p: String = "")
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
class DefaultArgsInNestedClassImpl {
annotation class Nested(val p: String = "")
}
// Incompatible because of bug KT-31636
actual typealias <!NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS!>DefaultArgsInNestedClass<!> = DefaultArgsInNestedClassImpl
@@ -24031,6 +24031,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/methodDefaultArgsViaActualTypealias_oldLanguageVersion.kt");
}
@Test
@TestMetadata("nestedAnnotationClassViaActualTypealias.kt")
public void testNestedAnnotationClassViaActualTypealias() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/defaultArguments/nestedAnnotationClassViaActualTypealias.kt");
}
@Test
@TestMetadata("nestedClassMethodsViaActualTypealias.kt")
public void testNestedClassMethodsViaActualTypealias() throws Exception {
@@ -153,6 +153,24 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizerTe
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@Test
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@Test
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@Test
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@Test
@TestMetadata("external.kt")
public void testExternal() throws Exception {
@@ -153,6 +153,24 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizerTe
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectClassesAndFunctions.kt");
}
@Test
@TestMetadata("expectNestedAnnotationClassWithConstructorParameter.kt")
public void testExpectNestedAnnotationClassWithConstructorParameter() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedAnnotationClassWithConstructorParameter.kt");
}
@Test
@TestMetadata("expectNestedClassMembers.kt")
public void testExpectNestedClassMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedClassMembers.kt");
}
@Test
@TestMetadata("expectNestedEnumClassGeneratedMembers.kt")
public void testExpectNestedEnumClassGeneratedMembers() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/expectNestedEnumClassGeneratedMembers.kt");
}
@Test
@TestMetadata("external.kt")
public void testExternal() throws Exception {