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

Getting "unused" warning from function annotated with "@discardableResult" #60276

Closed
stephencelis opened this issue Jul 28, 2022 · 7 comments · Fixed by #60324
Closed

Getting "unused" warning from function annotated with "@discardableResult" #60276

stephencelis opened this issue Jul 28, 2022 · 7 comments · Fixed by #60324
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@stephencelis
Copy link
Contributor

Describe the bug

I've started to see unused warnings crop up in Xcode 14 beta 4 for endpoints that are annotated with @discardableResult.

Steps To Reproduce

It's not always easy to reproduce, but I've specifically gotten them to appear in the following repo/project/file:

Steps to reproduce the behavior:

  1. Clone https://github.com/pointfreeco/swift-composable-architecture
  2. Check out d526b07053d46a740936e50be436f78c7ce7b092
  3. Open ComposableArchitecture.xcworkspace
  4. Navigate to VoiceMemosTests.swift
  5. Run tests, allow Xcode to type-check file, etc.
  6. Note that lines like this one have the warning:

    Warning: Result of call to function returning 'TestStoreTask' is unused

  7. Note that the function returning TestStoreTask is annotated with @discardableResult.

Expected behavior
I expect no warning.

Screenshots
image

Environment (please fill out the following information)

  • OS: macOS 11.0
  • Xcode 14 beta 4

Additional context
N/A

@stephencelis stephencelis added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jul 28, 2022
@LucianoPAlmeida LucianoPAlmeida added the diagnostics QoI Bug: Diagnostics Quality of Implementation label Jul 29, 2022
@tomguthrie
Copy link

We are also seeing this since beta 4. In our case it's only when the @discardableResult function is used within an async function / Task { ... }

@theblixguy
Copy link
Collaborator

theblixguy commented Jul 31, 2022

Small self-contained reproducer:

@discardableResult @MainActor
func a() async -> Int { 5 }

func b() async {
  await a()
}

I get this on 5.7:

<source>:3:11: warning: result of call to function returning 'Int' is unused
    await a()
          ^~~

But no such warning on 5.6.

Also, if you remove the @MainActor annotation the warning goes away.

@theblixguy
Copy link
Collaborator

I have opened a PR to fix it.

@dominikmayer
Copy link

I'm still seeing the warnings in Xcode version 14.0 (14A309). @dfeinzimer mentioned the same in #57477. Do you want to reopen this issue or should I create a new one?

@youngToMaturity
Copy link

Same here with @dominikmayer. Xcode version 14.0 (14A309) and warnings only surface for async methods.

@dornad
Copy link

dornad commented Sep 21, 2022

Same here with @loopbackseal. Xcode version 14.0.1 (14A400). Seems to still be contained to async methods.

@mredig
Copy link

mredig commented Sep 21, 2022

It's happening to me regardless of async methods.
Xnapper-2022-09-21-13 54 08

Xnapper-2022-09-21-13 54 44

(and this is just one of a little over 100 similar warnings - unsure how many are async vs not)

(Xcode Version 14.0 (14A309))

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. diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants