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-12936] create new {{-swift-version}} BEFORE we do {{#file}} != {{#filePath}} #55382

Open
weissi opened this issue Jun 4, 2020 · 3 comments
Assignees
Labels

Comments

@weissi
Copy link
Member

weissi commented Jun 4, 2020

Previous ID SR-12936
Radar rdar://problem/63991432
Original Reporter @weissi
Type Task
Additional Detail from JIRA
Votes 1
Component/s
Labels Task
Assignee @beccadax
Priority Medium

md5: a2e3c979da7982d47ebb958c678eb8da

Issue Description:

In Swift <= 5.2, you got the full file path with

func assertFoo(filePath: String: #file, line: Int = #line) { ... }

But in Swift 5.3+ I'm supposed to use

func assertFoo(filePath: String: #filePath, line: Int = #line) { ... }

which is incompatible with Swift 5.2. One idea to shim it is

#if compiler(>=5.3)
func _filePath(_ filePath: String = #filePath) { return filePath }
#else
func _filePath(_ filePath: String = #file) { return filePath }
#endif

func assertFoo(filePath: String = _filePath(), line: Int = #line) { ... }

which (deliberately) doesn't work (https://bugs.swift.org/browse/SR-12934). The only solution seems to be (thanks brentdax (JIRA User)) creating trampoline functions for every function that needs #filePath.

private func _assertFoo(filePath: String, line: Int) { ... }
#if compiler(>=5.3)
func assertFoo(filePath: String = #filePath, line: Int = #line) { _assertFoo(filePath: filePath, line: line) }
#else
func assertFoo(filePath: String = #file, line: Int = #line) { _assertFoo(filePath: filePath, line: line) }
#endif

This clearly isn't acceptable without introducing a new -swift-version preserving the behaviour in -swift-version 4, -swift-version 4.2, and -swift-version 5.

The only other option I see is to maybe make ((#file)) or something else that's valid in Swift 5.0 continue to mean #filePath.

@weissi
Copy link
Member Author

weissi commented Jun 4, 2020

CC brentdax (JIRA User)

@weissi
Copy link
Member Author

weissi commented Jun 4, 2020

@swift-ci create

@beccadax
Copy link
Contributor

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants