https://kotlinlang.org logo
#python-contributors
Title
# python-contributors
p

Piotr Krzemiński

07/21/2021, 7:27 AM
I'm working on translating field declarations (
visitField(declaration: IrField...
, branch translate-field-declarations), however it's tricky because in Python to be able to use some function, it has to be first defined. That's why now all box tests fail with:
Copy code
Traceback (most recent call last):
  File "/home/piotr/repos/kotlin-python/python/py.translator/testData/out/codegen/irBox/when/noElseInStatement_v5.py4568195347954504164/consumer.py", line 1, in <module>
    from compiled_module import box
  File "/home/piotr/repos/kotlin-python/python/py.translator/testData/out/codegen/irBox/when/noElseInStatement_v5.py4568195347954504164/compiled_module.py", line 1356, in <module>
    UNDEFINED_RESULT = UNDEFINED_RESULT_init_()
NameError: name 'UNDEFINED_RESULT_init_' is not defined
TODO: I think we need to do a similar thing that is done for JavaScript - move field assignments to the bottom, or reorder stuff in some other smart way. Leaving my work-in-progress change on the branch in case someone wants to tackle this problem. If not, I'll get back to it in a few days
1
b

bashor

07/21/2021, 3:23 PM
Note in JS we are going to switch to lazy init strategy for properties. It’s available under flag now and we going to make it default.
p

Piotr Krzemiński

07/21/2021, 3:25 PM
Yeah, good point. It would remove a need to reorder stuff. Thanks, will try this approach!
b

bashor

07/21/2021, 3:26 PM
From users POV it will work like on JVM
🆒 1
Also, there is an implementation for Kotlin/Native too
🙏 1
p

Piotr Krzemiński

07/22/2021, 4:40 AM
FTR, PropertyLazyInitLowering is responsible for making things lazy in K/JS. It's enabled if
-Xir-property-lazy-initialization
compiler flag is set. Also fun fact: it was me who reported a bug with incorrect ordering 3 years ago, so glad to see it being addressed 😄 https://youtrack.jetbrains.com/issue/KT-25796
👍 1
5 Views