Skip to content

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

Closed
@swift-ci

Description

@swift-ci
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfgood first issueGood for newcomersparserArea → compiler: The legacy C++ parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions