Swift block comment markers can fail to comment out code

Originator:lebpierre
Number:rdar://18138958 Date Originated:26-Aug-2014 11:27 PM
Status:Behaves correctly Resolved:No
Product:Developer Tools Product Version:Xcode 6
Classification: Reproducible:Always
 
Summary:
Contrary to their claimed behavior (of nesting cleanly), in some situations Swift block comment markers can fail to successfully comment out code.

Steps to Reproduce:
1. In a Swift playground, copy the following code:

println("The basic operators are +-*/%");

2. Modify it so that it reads:

/*
println("The basic operators are +-*/%");
*/

Expected Results:
After 2., the code is commented out without error.

Actual Results:
Xcode reports three errors:
- "Expected expression after unary operator" on line 2
- "Unterminated string literal" on line 2
- "Unexpected end of block comment" on line 3

Version:
Xcode Version 6.0 (6A280e) (aka Xcode6 beta6)
Mac OS X 10.9.4

Notes:
When fixing this bug, make sure there is no regression for this code:

/* I'd like to thank my family for introducing me to computers at an early age ":-) */

which is currently processed as a comment without error. Good luck.


There is, surprisingly, a workaround: adding a clever line before allows to create this:

// /*
println("The basic operators are +-*/%");

which can cleanly be commented out:

/*
// /*
println("The basic operators are +-*/%");
*/

However, it is hardly an elegant method…

C/C++/Objective-C has a similar issue, but it does not claim to always be able to comment out code using block comment markers, and has preprocessor directives (#if 0/#endif) to perform the job in that case; I do not know of such an alternative method in Swift.

Configuration:
N/A

Attachments:

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!