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-1895] compilation warning for void result type #44504

Closed
swift-ci opened this issue Jun 24, 2016 · 6 comments
Closed

[SR-1895] compilation warning for void result type #44504

swift-ci opened this issue Jun 24, 2016 · 6 comments
Assignees
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1895
Radar None
Original Reporter VladimirS (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 3.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @ahoppen
Priority Medium

md5: 256077fcd7fa34c0ecd899dc3c70f0c9

relates to:

  • SR-1752 Warning about unused result with ternary operator

Issue Description:

let s: String? = "hi"
s.map {print($0)}

we have:
warning: result of call to 'map' is unused
s.map {print($0)}

Isn't it strange that result of call is Void, but we have a warning? Don't
we need to suppress warning in this case?

@ahoppen
Copy link
Contributor

ahoppen commented Jun 24, 2016

This isn’t specifically a duplicate, but will be fixed in PR #3057 for SR-1752

@swift-ci
Copy link
Collaborator Author

Comment by Vladimir (JIRA)

got it.

@belkadan
Copy link
Contributor

The explanation: the result isn't Void, it's Void?. There's still a bit of information there: whether the map happened at all.

The prevailing opinion seems to be that this isn't enough information to force people to explicitly write _. Nothing's stopping them from checking it if they want.

@swift-ci
Copy link
Collaborator Author

Comment by Vladimir (JIRA)

I see. Agree that even Void? should not force to write _.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@TyrfingMjolnir
Copy link

TyrfingMjolnir commented May 20, 2023

$ uname -a
Darwin devmb15t.lan 21.6.0 Darwin Kernel Version 21.6.0: Thu Mar  9 20:08:59 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_X86_64 x86_64

XCode Version 14.2 (14C18)

Do I experience this same issue?

var outputFile: [ Int ] = []
[ 0x01 ].map { outputFile.append( $0 ) }

At least the error message is the same: Warning: result of call to 'map' is unused

Issue still with

uname -a
Darwin XCode01.lan 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64

XCode Version 14.3 (14E222b)

Then again issue does not show in Apple XCode's Playground, only projects.

@tbkka
Copy link
Contributor

tbkka commented May 22, 2023

Really, you should not use map for this. Use a for loop; it's easier to read.

var outputFile: [ Int ] = []
[ 0x01 ].map { outputFile.append( $0 ) }

Basically, map should never be used for side-effects like this.

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

No branches or pull requests

5 participants