Xcode 10.2: Swift 5 conversion leads to spurious compiler error

Originator:rsfinn
Number:rdar://49463569 Date Originated:2019-03-31
Status:Duplicate/48634159 (Closed) Resolved:
Product:Developer Tools Product Version:Xcode 10.2 (10E125)
Classification: Reproducible:Always
 
Summary:
A Swift project uses an enumeration type defined in Objective-C, and contains a switch statement that switches on a variable of this type. One of the enumeration constants is invalid in this context, so the last switch case ends with an early return statement. 

When this project is opened in Xcode 10.2 and migrated to Swift 5, an compiler warning appears on the switch statement: "Switch covers known cases, but 'Player' may have additional unknown values", with the suggested fixit 'Handle unknown values using "@unknown default"'.  

Accepting the fixit results adds the text "@unknown default:" on the line following the early return statement mentioned above. This causes Xcode 10.2 to report an incorrect error "Expected expression in 'return' statement" on the return statement, although the containing function returns no value (and the statement was accepted before the fixit was applied).

Steps to Reproduce:
1. Open the attached project in Xcode 10.2.
2. Perform the migration to Swift 5.
3. Observer the compiler warning on the switch statement.
4. Accept the suggested fixit to add an "@unknown default:" case to the switch.

Expected Results:
The updated code does not cause a compiler message.

Actual Results:
The updated code causes Xcode 10.2 to issue a compiler error message on the line containing the bare "return" statement; the error message "Expected expression in 'return' statement" should not apply to this statement.

Note:
It appears to be possible to work around the spurious error by changing "@unknown default:" to "@unknown case _:", but this should not be necessary.

It is also possible to work around the error by changing the bare "return" statement to "return ()", but again this should not be necessary.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!