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

@discardableResult doesn't work with computed property getter #72752

Open
li3zhen1 opened this issue Apr 1, 2024 · 0 comments
Open

@discardableResult doesn't work with computed property getter #72752

li3zhen1 opened this issue Apr 1, 2024 · 0 comments
Labels
accessors Feature → declarations: Variable (property) accessors attributes Feature: Declaration and type attributes bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself declarations Feature: declarations @discardableResult Feature → attributes: The @discardableResult attribute swift 6.0 type checker Area → compiler: Semantic analysis unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@li3zhen1
Copy link
Contributor

li3zhen1 commented Apr 1, 2024

Description

No response

Reproduction

struct S {
    var discardableGetter: Int {
        @discardableResult
        get {
            return 0
        }
    }
}

func test() {
    S().discardableGetter
}
../discardableGetter.swift:11:9: warning: expression of type 'Int' is unused
 9 │
10 │ func test() {
11 │     S().discardableGetter
   │         ╰─ warning: expression of type 'Int' is unused
12 │ }

Expected behavior

@discardableResult could suppress this warning.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

also occur in nightly:

Swift version 6.0-dev (LLVM a8cd54c4da01fef, Swift e738059)
Target: arm64-apple-macosx14.0

Additional information

Similar to #71870 .

@li3zhen1 li3zhen1 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 1, 2024
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis attributes Feature: Declaration and type attributes @discardableResult Feature → attributes: The @discardableResult attribute unexpected behavior Bug: Unexpected behavior or incorrect output swift 6.0 accessors Feature → declarations: Variable (property) accessors declarations Feature: declarations and removed triage needed This issue needs more specific labels labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessors Feature → declarations: Variable (property) accessors attributes Feature: Declaration and type attributes bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself declarations Feature: declarations @discardableResult Feature → attributes: The @discardableResult attribute swift 6.0 type checker Area → compiler: Semantic analysis unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

No branches or pull requests

2 participants