[SR-7999] Adding optional arrays produces unexpected result #50532
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: e7443c8cd248c361249a2a21b6079fac
Issue Description:
Tested on Xcode 10 beta 1/Swift 4.2
If you have two optional arrays and add their contents into a new result variable, you might lose the contents of the right-hand array if you don't properly wrap both arrays in parenthesis when nil coalescing.
It's unclear if this is a compiler bug, or defined behavior if you know what's going on, but the results of this are unexpected so I'm considering it a bug.
Observe the following reproducible code snippet:
The first concatenation compiles, as you have to use at least one set of parenthesis, however this produces an unexpected result as it completely drops the contents in array2. The second concatenation compiles and produces the expected result by concatenating the contents of both arrays.
The text was updated successfully, but these errors were encountered: