getOrDefault() not working in javascript?


We have some code shared between javascript and JVM, but unit tests are run on JVM.

It seems Map.<Char,Char> . getOrDefault(‘a’,‘a’) returns null when ‘a’ is not in the map on javascript, but will return ‘a’ on the JVM. getOrDefault(‘a’,‘a’) ?: ‘a’ works as a fix on javascript, but perhaps only ‘get’ is available on this platform?


Kotlin is a statically typed language, so if a method does not exists, compiler should report an error. You get an unexpected result on run time. This means that there’s an issue in Kotlin stdlib implementation for JavaScript.


And here’s the issue:


I have searched in jar for PlatformDependent and it looks like only these two methods are market
Are there other stubs in kotlin.js ?


Thanks Alexey. The issue explains things well.

And sorry for my imprecise wording. I do realise that if a method does not exist you should get an error, I was just postulating that the reality for now better to use ‘get’ with ?: in place of getOrDefault. I will pay more attention to wording :slight_smile: