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-3258] #file keyword doesn't work inside interpolated default argument #45846

Closed
keith opened this issue Nov 22, 2016 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@keith
Copy link
Collaborator

keith commented Nov 22, 2016

Previous ID SR-3258
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: e16b6eb5c97868b70239d2d1d9c5bc0b

is duplicated by:

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

Issue Description:

Example:

func foo(bar: String = "\(#file)", baz: String = #file) {
    print(bar == "") // prints true
    print(baz)       // prints the full path of the file
}

foo()

I'm not sure if this is expected or not, but if it is I guess it would be ideal to not allow #file to be used here.

@CodaFi
Copy link
Member

CodaFi commented Nov 23, 2016

@jckarter It looks like SILGen is a little too happy to set `overrideLocationForMagicIdentifiers` here. I'm not sure if that means Sema needs to handle the literal expansion here or if overrideLocationForMagicIdentifiers should be unset here. The tests mention something about "not leaking details about the source' so I'm wary of getting rid of it altogether.

@jckarter
Copy link
Member

I'm not sure what the comment would be referring to, since #file kind of fundamentally "leaks details about the source". I don't see why a string interpolation would be any worse than a bare #file in that regard.

@belkadan
Copy link
Contributor

belkadan commented Dec 9, 2016

If #file within an interpolation expanded to the name of the callee's file rather than the caller's—which I suspect it would—and if we put default argument evaluation in the caller instead of the callee—which we intend to—then the comment would make sense. But the behavior would remain not what the user would expect.

@CodaFi
Copy link
Member

CodaFi commented Oct 21, 2017

@slavapestov incidentally resolved this with #10200

@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

4 participants