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-4459] Source location literals not set (#file, #function, #line) #47036

Closed
swift-ci opened this issue Apr 1, 2017 · 0 comments
Closed

[SR-4459] Source location literals not set (#file, #function, #line) #47036

swift-ci opened this issue Apr 1, 2017 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 1, 2017

Previous ID SR-4459
Radar None
Original Reporter martin9612 (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 3.1, Xcode 8.3 (8E162), macOS 10.12.4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: df4b14851de2e69520b917dc60d8d045

duplicates:

  • SR-4325 Changed value of #file on 3.1 snapshot

Issue Description:

Hi There

When upgrading an existing project from Swift 3.0 to 3.1 some of my unit test started failing due to properties in an enum not being initialised via #file, #function, #line.

Observed outcome:
Enum properties initialised via #file, #function, #line are empty.

Expected outcome:
Enum properties initialised via #file, #function, #line contain the source location.

Example code:

public enum MyEnum {
    case SourceLocation(file: String, function: String, line: Int)
}

class Main {
    private let initialisedEnum =
        MyEnum.SourceLocation(file: #file, function: #function, line: #line)
    
    func run() {
        print("Swift 3.1 XCode 8.3 initialisation issue")
        if case .SourceLocation(let file, let function, let line) = initialisedEnum {
            print("file: \"\(file)\"")
            print("function: \"\(function)\"")
            print("line: \(line)")
        }
    }
}

let main = Main()
main.run()
Swift 3.1 XCode 8.3 initialisation issue
file: ""
function: ""
line: 0
Program ended with exit code: 0

Condition:
The problem only occurs, if the variable initialisedEnum is declared and initialised in the class. If the variable is declared and initialised outside the class or within the function run(), it works as expected. It also works, if the variable is declared in the class and initialised in a constructor.

Cheers
Martin

@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
Projects
None yet
Development

No branches or pull requests

1 participant