Closed streetsofboston closed 4 years ago
This code makes the compiler crash. The bug is know and referenced here: https://youtrack.jetbrains.com/issue/KT-31135
class foo(var bar : String) fun main() { var baz : foo? = foo("test") baz?.bar += "test" }
It seems to be relate to the fact that
+=
String
baz?.bar = baz?.bar + "test"
plus
operator fun String?.plus(other: Any?): String
Rewriting it by hand, this bug goes away. It looks like the compiler messes up the re-write.
If the plus's receiver were non-nullable, a compiler error would have been generated instead of it crashing.
This code makes the compiler crash. The bug is know and referenced here: https://youtrack.jetbrains.com/issue/KT-31135
It seems to be relate to the fact that
+=
is operated on an immutable class (String
) and the statement is re-written asbaz?.bar = baz?.bar + "test"
andplus
extension function on aString
takes a nullable receiver:operator fun String?.plus(other: Any?): String
Rewriting it by hand, this bug goes away. It looks like the compiler messes up the re-write.
If the
plus
's receiver were non-nullable, a compiler error would have been generated instead of it crashing.