[JS IR] Make JsExport not fail on companion objects (KT-37829)

This commit is contained in:
Svyatoslav Kuzmich
2020-10-07 08:38:27 +03:00
parent 9f716ba37c
commit 5e5712afbb
4 changed files with 22 additions and 7 deletions
@@ -171,8 +171,11 @@ class ExportModelGenerator(val context: JsIrBackendContext) {
} }
is IrField -> { is IrField -> {
assert(candidate.correspondingPropertySymbol != null) { assert(
"Properties without fields are not supported ${candidate.fqNameWhenAvailable}" candidate.origin == IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE
|| candidate.correspondingPropertySymbol != null
) {
"Unexpected field without property ${candidate.fqNameWhenAvailable}"
} }
} }
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.builders.declarations.buildField import org.jetbrains.kotlin.ir.builders.declarations.buildField
import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildFun
import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.types.makeNullable import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
@@ -47,6 +44,7 @@ class ObjectDeclarationLowering(
name = Name.identifier(declaration.name.asString() + "_instance") name = Name.identifier(declaration.name.asString() + "_instance")
type = declaration.defaultType.makeNullable() type = declaration.defaultType.makeNullable()
isStatic = true isStatic = true
origin = IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE
}.apply { }.apply {
parent = declaration.parent parent = declaration.parent
initializer = null // Initialized with 'undefined' initializer = null // Initialized with 'undefined'
@@ -49,5 +49,11 @@ declare namespace JS_TESTS {
foo(): number; foo(): number;
}; };
function takesO(o: typeof foo.O): number; function takesO(o: typeof foo.O): number;
class KT_37829 {
constructor();
readonly Companion: {
readonly x: number;
};
}
} }
} }
@@ -93,4 +93,12 @@ object O {
} }
fun takesO(o: O): Int = fun takesO(o: O): Int =
O.x + O.foo() O.x + O.foo()
// Test that JsExport with companion object compiles without error.
// Usage is not supported yet.
class KT_37829 {
companion object {
val x = 10
}
}