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-8464] Attempting to print a function should require the use of String(describing:) #50985

Closed
swift-ci opened this issue Aug 5, 2018 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Aug 5, 2018

Previous ID SR-8464
Radar rdar://problem/43057055
Original Reporter Noobish1 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OSX 10.13.4, Swift 4.1.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee mzp (JIRA)
Priority Medium

md5: 2159d86fd9242cba4e2213665cb5c218

Issue Description:

I ran into a scenario that wasn't very nice when transforming a computed property into a function that wasn't very nice and lead to a bug in my code.

I had a computed property `X` on object `A` and I used that computed property in a string using interpolation (`"my computed property is (a.X)"`).

I later transformed X into a function so it became `X(someArg: SomeThing)`.

My old code that used it in string interpolation still built and compiled fine but now resulted in it trying to print the function instead of printing the result of the function call. It would be good if we could require the use of `String(describing🙂` when printing functions in the same way that we require it for printing `Optional`s.

@jckarter
Copy link
Member

jckarter commented Aug 6, 2018

@swift-ci create

@jckarter
Copy link
Member

jckarter commented Aug 6, 2018

Starter bug hint: Like Blair says, we provide this warning for Optional already; it should be possible to look at the compiler to see how that warning works to extend it to also warn about functions in printing or string interpolation contexts.

@dabrahams
Copy link
Collaborator

I'm not at all sure we should do this. You could change the type of any name and come up with the same complaint, that functionality that works with any type T continued to compile but "surprisingly" changed behavior. What makes this case special?

@jckarter
Copy link
Member

jckarter commented Aug 6, 2018

Printing functions is useless most of the time, and we warn with a fixit in most other situations where there's a type mismatch due to an unapplied function.

@swift-ci
Copy link
Collaborator Author

Comment by MIZUNO Hiroki (JIRA)

Create a pull request to resolve this: #19234

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants