i'm seeing some weird behavior with the js compile...
# javascript
n
i'm seeing some weird behavior with the js compiler. i'm wondering if i'm doing something wrong, or if it's an issue with the compiler. the behavior is the same with both IR and legacy compilers. code snippets in thread.
youtrack 1
Kotlin:
Copy code
var foo = foos[parentKey]?.find { it.typeCode == typeCode }!!
compoundKey.split("/").forEach { key ->
    val selectedBar = bars.find { it.barKey == key }!!
    val newBars = foo.bars.toMutableList()
    newBars.removeAll { it.barKey == key }
    newBars += selectedBar
    foo = foo.copy(bars = newBars)
}
(sorry, this was hard to obfuscate)
Compiled js
Copy code
var tmp$;
            var $receiver = tmp$;
            var find$result;
            var firstOrNull$result;
            firstOrNull$break: do {
                var tmp$_0;
                tmp$_0 = $receiver.iterator();
                while (tmp$_0.hasNext()) {
                    var element = tmp$_0.next();
                    if (element.typeCode === typeCode) {
                        firstOrNull$result = element;
                        break firstOrNull$break;
                    }
                }
                firstOrNull$result = null;
            } while (false);
            find$result = firstOrNull$result;
            var foo = {
                v: ensureNotNull((tmp$ = closure$foos.get_11rb$(parentKey)) != null ? find$result : null)
            };
$receiver
is undefined when
$receiver.iterator()
is called. however, if i change
foo
to a
val
instead of
var
, i don't have this problem. obviously i have to comment out the reassignment for that to compile, but that is the only material change -- it still fails with
var
when there is no reassignment
r
You should probably create a reproducible sample project and open an YouTrack issue.
👍 2
2
n
i'll see what i can do