Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-615] Swift compiler cannot handle source files with UTF-8 header bytes #43232

Closed
swift-ci opened this issue Jan 25, 2016 · 3 comments
Closed
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-615
Radar None
Original Reporter dwarfland (JIRA User)
Type Bug
Status Closed
Resolution Done

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
Votes 0
Component/s Compiler
Labels Bug, Parser, StarterBug
Assignee tanadeau (JIRA)
Priority Medium

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.

@swift-ci
Copy link
Collaborator Author

Comment by Trent Nadeau (JIRA)

This also occurs in the latest Swift 2.2 and 3.0 binaries on Ubuntu 14.04.

@swift-ci
Copy link
Collaborator Author

Comment by Trent Nadeau (JIRA)

I think I know how to fix this.

@swift-ci
Copy link
Collaborator Author

Comment by Trent Nadeau (JIRA)

Created PR at #1100

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant