[SR-615] Swift compiler cannot handle source files with UTF-8 header bytes #43232
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
good first issue
Good for newcomers
parser
Area → compiler: The legacy C++ parser
Attachment: Download
Environment
Swift as shipped in Xcode 7.0 or 7.3 running on Mac OS X El Capitan 10.3 or 10.3
Additional Detail from JIRA
md5: ced5f486782db81069be6f6c3a2383f8
Issue Description:
Try to compile the attached main.swift file. It's a plain Swift file whit two simple lines of code, and opened in Xcode it looks fine. But, it has a standard UTF-8 header marker, with the first three bytes of the file reading EF BB BF.
This causes the Swift compiler to not build the file, instead emitting these "unexpected" errors:
main.swift:1:10: Consecutive statements on a line must be separated by ';'
main.swift:1:1: Use of unresolved identifier 'import'
main.swift:1:11: Use of unresolved identifier 'Foundation'
This is not an issue when only working in Xcode, but it causes problems when editing source files with other editors or IDEs that write such a header — which is perfectly legitimate.
By contrast, Clang/LLVM will compile ObjC .h/.m files with such a header just fine.
Attached: a project that illustrates the issue, as well as two screenshots showing (a) the errors emitted in Xcode and (b) the content ion the file in a hex viewer.
The text was updated successfully, but these errors were encountered: