krzema12 / kotlin-python

Python target for the Kotlin Programming Language. See https://github.com/krzema12/kotlin-python/tree/python-backend/python
https://discuss.kotlinlang.org/t/idea-python-backend/19852
48 stars 1 forks source link

Optimize `Unit` returns #70

Open krzema12 opened 2 years ago

krzema12 commented 2 years ago

Originally created by @SerVB.

If it's just Unit, just return Python's None; if it's nullable (Unit?), then do some more complex logic like null -> None and Unit -> Unit.getInstance(). However doing this will also require being careful with Unit assignments, for example, if there is code like val b = println(), it should be compiled like println(); val b = Unit (achievable via introducing an extra lowering) because println() will return None and it's not what we want to assign to b.

SerVB commented 2 years ago

Related fix on the JS side: https://youtrack.jetbrains.com/issue/KT-51127#focus=Comments-27-5940910.0-0 / https://github.com/jetbrains/kotlin/commit/51bb548aefc5a536dfaa540357964eb4fbd0391c (remove Unit_getInstance calls in statements)