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-11222] Magic literal default args don't use caller info if nested in another expression #53623

Closed
hamishknight opened this issue Jul 29, 2019 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself SILGen Area → compiler: The SIL generation stage

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-11222
Radar None
Original Reporter @hamishknight
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift version 5.1-dev (LLVM 200186e28b, Swift b8b7384)
Target: x86_64-apple-darwin18.5.0

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

md5: 26236d95a5fcdfe29a8e9d2b794643db

duplicates:

  • SR-6913 Default arguments are not evaluated correctly in larger expression

Issue Description:

As the following example demonstrates, #function only evaluates to the caller's function name when at the top-level of a default arg expression:

func foo(_ fn: String = #function, _ file: String = #file) {
  print(fn)
}

func bar(_ x: (fn: String, file: String) = (#function, #file)) {
  print(x.fn)
}

func qux() {
  foo() // Prints: qux()
  bar() // Prints: bar(_:)
}
qux()

Arguably both cases should evaluate to qux(). This is even the case when wrapping it in parentheses:

func foo(_ fn: String = (#function)) {
  print(fn)
}

func qux() {
  foo() // Prints foo(_:) instead of qux().
}
qux()
@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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

1 participant