[JS IR] Make JsExport not fail on companion objects (KT-37829)
This commit is contained in:
+5
-2
@@ -171,8 +171,11 @@ class ExportModelGenerator(val context: JsIrBackendContext) {
|
||||
}
|
||||
|
||||
is IrField -> {
|
||||
assert(candidate.correspondingPropertySymbol != null) {
|
||||
"Properties without fields are not supported ${candidate.fqNameWhenAvailable}"
|
||||
assert(
|
||||
candidate.origin == IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE
|
||||
|| candidate.correspondingPropertySymbol != null
|
||||
) {
|
||||
"Unexpected field without property ${candidate.fqNameWhenAvailable}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -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.declarations.buildField
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
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.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -47,6 +44,7 @@ class ObjectDeclarationLowering(
|
||||
name = Name.identifier(declaration.name.asString() + "_instance")
|
||||
type = declaration.defaultType.makeNullable()
|
||||
isStatic = true
|
||||
origin = IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE
|
||||
}.apply {
|
||||
parent = declaration.parent
|
||||
initializer = null // Initialized with 'undefined'
|
||||
|
||||
@@ -49,5 +49,11 @@ declare namespace JS_TESTS {
|
||||
foo(): 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 =
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user