Skip to content

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

Open
@li3zhen1

Description

@li3zhen1

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    @discardableResultFeature → attributes: The @discardableResult attributeaccessorsFeature → declarations: Variable (property) accessorsattributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdeclarationsFeature: declarationsswift 6.0type checkerArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions