Is and when for traits in Javascript



I have noticed that type checks (is- and when-expressions) in the Javascript backend doesn’t seem to work for traits.

The following code works in the jvm but not in javascript:

trait Fruit {} open class Apple : Fruit {} class RedApple : Apple() {} fun main(args : Array<String>) {   val apple = RedApple()   if (apple is RedApple) println("apple is RedApple")   if (apple is Apple) println("apple is Apple")   if (apple is Fruit) println("apple is Fruit") }

In java "apple" is a Fruit, an Apple and a RedApple. But in Javascript it is only an Apple and a RedApple.

My question is: do you plan to fully support traits in the javascript-backend in the future?

/Tobias W



First of all it’s a bug. Feel free to report it to tracker.

The answer is yes, we plan to support traits including type checks for them (for those that come from kotlin code).

If you find any more issues, please let me know.



Thanks for the answer.

I have reported this bug as: