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-5242] #sourceLocation rejected at end of extension/struct/class/enum declarations #47817

Closed
lorentey opened this issue Jun 16, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself parser Area → compiler: The legacy C++ parser regression swift 4.0

Comments

@lorentey
Copy link
Member

Previous ID SR-5242
Radar None
Original Reporter @lorentey
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.0Regression, Parser
Assignee @rintaro
Priority Medium

md5: 54dbda83eea091fe20ef30129991e0c7

Issue Description:

In generated Swift code, I use the #sourceLocation directive to map source lines to the corresponding location in my input files. Because the mapping may not exactly correspond to the syntactic structure of Swift, I expect to be able to use the directive at any position in Swift code.

In Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8), the compiler produces an error when a #sourceLocation directive appears before the closing brace of an extension, struct, class, enum, or protocol declaration.

For example, the following code used to compile in Swift 3.2:

extension Int {
  var isEven: Bool {
    return self & 1 == 0
  }
  #sourceLocation(file: "Foobar.swift", line: 1)
}

The Swift 4 compiler, however, produces the following diagnostic:

Foobar.swift:1:1: error: expected declaration
}
^
test.swift:1:1: note: in extension of 'Int'
extension Int {
^

I can work around the error by adding a dummy member after the #sourceLocation directive, but that is not always a viable option in generated code.

@belkadan
Copy link
Contributor

@rintaro, did something change recently?

@rintaro
Copy link
Mannequin

rintaro mannequin commented Jun 20, 2017

Yes, the issue was introduced in #6979
I'll fix this.

@rintaro
Copy link
Mannequin

rintaro mannequin commented Jun 23, 2017

#10485 merged
Thanks for reporting @lorentey!

@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 parser Area → compiler: The legacy C++ parser regression swift 4.0
Projects
None yet
Development

No branches or pull requests

3 participants