Hey, what's wrong here? I don't get any syntax err...
# announcements
s
Hey, what's wrong here? I don't get any syntax error but compilator crashes with this message:
Copy code
Cause: Label wasn't found during iterating through instructions
Element is unknownThe root cause was thrown at: LabelNormalizationMethodTransformer.kt:148
Oh, this also causes a compilator crash:
Copy code
class foo(var bar : String)

fun main() {    
    var baz : foo? = foo("test")
    baz?.bar += "test"
}
s
Is it because may be trying to assign a value to a
null
property…?
baz?.bar
could be null. Then you may wind up with
null += test
. This should not compile. But instead of a compiler error you get a compiler crash…
I get the same error
s
But ?. operator ensures that you work on an instance
s
What you’d want is
baz?.let { it.bar += test }
This is a simplified version of the bug you found:
Copy code
class Container(
    var value : String = ""
)

fun bug() {
    val container : Container? = null
    container?.value += "2"
}
It seems to come from the
+=
operator with an optional/nullable left-hand side expression
s
Yep, because
?.plus()
seems to work
But if value is non nullable and property is called safely, why it needs safe call?
s
I think since a
String
is a immutable class, the
+=
is not a
plusAssign
. It probably rewrites it a
object = object + param
, which may fail….
Rewriting it manually works….
Copy code
class Container(
    var value : String = ""
)

fun bug() {
    val container : Container? = null
    container?.value = container?.value + "2"
}
You should file a bug.
s
It is already filled
💯 1
s
Do you have the link to the bug? I’d love to share it with my teams here. Thank you!
s