Swift allows U+00AD as a character in identifiers. This is the "soft hyphen" and is normally invisible.

Originator:keith.ray
Number:rdar://32053823 Date Originated:08-May-2017
Status:Open Resolved:
Product:Swift compiler Product Version:Xcode 8.1
Classification:ui Reproducible:
 
Create swift source code containing an identifier containing the soft hyphen character. This is an invisible character in most editors. 

It will confuse users because the same sequence of characters without the soft hyphen will look the same, but not match.

The soft hyphen is documented as a legal character in this page:
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html 

identifier-head → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA

Steps to Reproduce:
run this code in a Swift playground:

 if let u = UnicodeScalar(0x00ad) { // U+00AD is a legal character
     let c : Character = Character(u)
     print("import Foundation\n\nvar invisible\(c)hypen = 12\n")
 }

copy the output into the same playground or another one.

the variable looks like "invisiblehyphen" but contains the invisible hyphen character.

Expected Results:
I thing this character should not be allowed in identifiers, and the Swift compiler should issue an invalid character error message if the soft hyphen character is in an identifier or anywhere other than a string (and maybe not then?)

Actual Results:
compiler fails to recognize "invisiblehyphen" (with no U+00AD character) as the same identifier as the one copied from the output that does contain U+00AD.

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!