Closed krzema12 closed 2 years ago
I'm testing with:
class MultiConstructors1(a: Int) {
init {
val s = "body 1"
}
constructor(b: String) : this(2) {
val s = "body 2"
}
}
class MultiConstructors2 {
constructor(a: Int) {
val s = "body 3"
}
constructor(b: String) {
val s = "body 4"
}
}
But compilation now fails with:
exception: java.lang.ClassCastException: org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl cannot be cast to org.jetbrains.kotlin.ir.expressions.IrExpression
at org.jetbrains.kotlin.ir.backend.py.lower.SecondaryConstructorLowering$generateInitBody$1.invoke(SecondaryCtorLowering.kt:124)
...
I suggest adding e2e test for constructors.
This PR tries to solve the problem described in this doc: https://github.com/krzema12/kotlin-python/wiki/Notes-on-getting-rid-of-%22NameError:-name-'Object_create'-is-not-defined%22
Regressions:
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Classes > testSelfcreate
Calling base class constructor inside the primary constructor got broken. To fix it, one has to check in which context the constructor is called, and create a relevant kind of call.