JS backend M9 trouble

I've got some code like this:

  if (c.lastLogin > 0) { …

And it’s generating JS like this:

  if (c.lastLogin.compareTo_za3rmp$(Kotlin.Long.fromInt(0)) > 0) {

Which is crashing.  c.lastLogin.compareTo_za3rmp$ is undefined.

Any ideas?

Rob

Hi, Rob

Could you show all sorces or other example where we can reproduce it?
Could you show full generated code?

I think I see what it is. It's not M9's fault. I'm doing something shady, and while M8 let me get away with, M9 is not.  I have class declared, something like this:

class User {
  var id = 0
  var name = “”
  var lastLogin: Long = 0
}

But at runtime the actual instances are simply JSON data, created outside Kotlin’s control in native Javascript. And then when Kotlin refers to them using this type, I see it expects something more than the simple Javascript number for that lastLogin property.

I’d like to get JSON data from server and refer to it in a typesafe way, but it’s not right to simply cast something like  { id: 0, name: ‘Joe’, lastLogin: 123 } (JSON) to a User and expect it to work.

Rob

It should work if you replace Long with Int.

Or a Double? In this case it's a date in milliseconds so I'm worried about overflows.  Though maybe "Int" won't overflow in JS like it does in JVM?

Rob

Hi, Rob!

Both Int and Double translates to JS number, so I think You’ll get the same behavior at runtime.
And yes “Int” won’t overflow in JS because at runtime it’s JS number which is the same as JVM Double.