Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements around constructors #37

Closed
wants to merge 1 commit into from
Closed

Conversation

krzema12
Copy link
Owner

@krzema12 krzema12 commented Sep 27, 2021

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
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Classes$Inner > testProperOuter
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Closures$CaptureInSuperConstructorCall > testKt4174
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Closures$CaptureInSuperConstructorCall > testOuterAndLocalCapturedInLocalClass
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Closures$CaptureInSuperConstructorCall > testOuterEnumEntryCapturedInLambdaInInnerClass
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenBoxTestGenerated$Closures$CaptureInSuperConstructorCall > testProperValueCapturedByClosure1
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenInlineTestGenerated$AnonymousObject > testSuperConstructorWithObjectParameter
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenInlineTestGenerated$Enum > testValueOf
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenInlineTestGenerated$Enum > testValueOfCapturedType
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenInlineTestGenerated$Enum > testValueOfChain
org.jetbrains.kotlin.python.test.ir.semantics.IrPythonCodegenInlineTestGenerated$Enum > testValueOfChainCapturedType

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.

     def __init__(self, this_0):
         self.this_0 = this_0
-        A.__init__(self, this_0.b)
+        A(this_0.b)

@krzema12 krzema12 changed the title WIP: improvements around constructors Improvements around constructors Sep 27, 2021
@SerVB
Copy link
Collaborator

SerVB commented Oct 1, 2021

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.

@SerVB SerVB mentioned this pull request Oct 8, 2021
@krzema12 krzema12 closed this Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants