Hi, I just found weird behaviour in our JetPack Co...
# compose-web
t
Hi, I just found weird behaviour in our JetPack Compose for Web. project Here is scenario: File
FileA.kt
Copy code
package mypackage

import org.jetbrains.compose.web.css.px

val a = 96.px
File
MyTest.kt
Copy code
package mypackage 

val b = a

class StyleSheetTest {

    @Test
    fun testA() {
        val result: CSSCalcValue<CSSUnitLength> = 100.vw - 2 * a
        assertEquals("calc(100vw - 192px)", result.toString())
    }

    @Test
    fun testB() {
        val result: CSSCalcValue<CSSUnitLength> = 100.vw - 2 * b
        assertEquals("calc(100vw - 192px)", result.toString())
    }
}
testB
fails with
TypeError: Cannot read properties of undefined (reading 'value')
@Akif Abasov [JB] any idea what is wrong? Is that compiler bug or some edge case optimalization in Kotlin JS IR compiler?
a
At first sight it could be problem with initialisation order. And it looks like problem of Kotlin JS/IR.
something like
val b = a
executed before
val a = 96.px
you can check it with
println(b)
in test. It will print
undefined
if i’m right.
t
Also changing of
FileA.kt
to
Copy code
val a
get() = 96.px
helps.
a
So it definitely is initialisation order problem.
And this is common Kotlin/JS problem. Can’t help with it 😞
t
It is.
println(b)
really prints
undefined
No problem when I can workaround.
I just wanted to make sure what's wrong.
n
No problem when I can workaround.
Nice catch, please report an issue if you have some time...
t
@Norbi where to report? My understanding is that it is Kotlin IR/JS feature.
n
it is Kotlin IR/JS feature
It seems to be a bug, not a feature.
t
@Akif Abasov [JB] is that bug that I should report to Kotlin/JS team? Or is that just a weird feature?
a
I’m not sure if it is feature. It most likely that it’s just designed that way for now. But i’m sure that there should be compile time check for such problems. Because compiler knows an order and it could check if it’s wrong (and in this case it even could be fixed by compiler). So… it isn’t bug, but huge usability problem for me.
e
if FileA and MyTest circularly depend on each other, then I don't think there's anything the Kotlin compiler can do. but if the dependency is only one way, this seems like a bug
👍 1
t
Ok, I'll report it and let Kotlin JS team to evaluate whether it is bug or feature.
🙏 1
h
Does it work with LazyPropertyInit? https://youtrack.jetbrains.com/issue/KT-43222
👍 2
☝️ 2
t
I'll check but I didn't work on build scripts so it may take me some time.
l
FYI, the place to report Kotlin issues is simply kotl.in/issue