This was a fairly hard bug to find in my code but once i found it i was surprised the compiler didn’t catch it or understand why it was valid.
val my_string =
"abc" +
"def"
"ghi"
The value of my_string ended up being "abcdef" since i missed the + sign after "def". Why didn’t the compiler complain and what happened to "ghi"?
The code is valid because
"ghi"is a valid expression on its own.If this is inside a function (and not followed by anything else) then
"ghi"is the return value of that function. Otherwise it’s just ignored (like if you’d written42 + 23on a line on its own).