Psi2ir: do not generate default accessor body for expect properties

Because generateDefaultGetterBody/generateDefaultSetterBody reference
the property's backing field, which in case of extension properties
leads to an error "Unbound symbols not allowed" because extension
property cannot have a backing field.

In some way, this check is similar to the `isExpect` check in
`generatePrimaryConstructor`.
This commit is contained in:
Alexander Udalov
2021-03-09 15:35:57 +01:00
parent 5fc9f3bc17
commit bdaeaca5ae
10 changed files with 71 additions and 3 deletions
@@ -24540,6 +24540,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/multiplatform/expectClassInJvmMultifileFacade.kt");
}
@Test
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.Name.isValidIdentifier
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.pureEndOffset
import org.jetbrains.kotlin.psi.psiUtil.pureStartOffset
@@ -137,8 +136,8 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
private fun generateDefaultAccessorBody(
accessor: PropertyAccessorDescriptor,
irAccessor: IrSimpleFunction
) =
if (accessor.modality == Modality.ABSTRACT)
): IrBlockBody? =
if (accessor.modality == Modality.ABSTRACT || accessor.correspondingProperty.isExpect)
null
else
when (accessor) {
@@ -0,0 +1,26 @@
// !LANGUAGE: +MultiPlatformProjects
// FILE: common.kt
package test
expect val v: String
expect val Char.extensionVal: String
expect var String.extensionVar: Char
// FILE: jvm.kt
package test
actual val v: String = ""
actual val Char.extensionVal: String
get() = toString()
actual var String.extensionVar: Char
get() = this[0]
set(value) {}
fun box(): String =
v + 'O'.extensionVal + "K".extensionVar
@@ -24540,6 +24540,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/multiplatform/expectClassInJvmMultifileFacade.kt");
}
@Test
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -24540,6 +24540,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multiplatform/expectClassInJvmMultifileFacade.kt");
}
@Test
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -20804,6 +20804,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/multiplatform/expectClassInJvmMultifileFacade.kt");
}
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/noArgActualConstructor.kt");
@@ -16377,6 +16377,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@TestMetadata("optionalExpectation.kt")
public void testOptionalExpectation() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt");
@@ -15834,6 +15834,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@TestMetadata("optionalExpectation.kt")
public void testOptionalExpectation() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt");
@@ -15899,6 +15899,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@TestMetadata("optionalExpectation.kt")
public void testOptionalExpectation() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt");
@@ -9740,6 +9740,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("expectProperty.kt")
public void testExpectProperty() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/expectProperty.kt");
}
@TestMetadata("optionalExpectation.kt")
public void testOptionalExpectation() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/optionalExpectation.kt");