Skip to content

@discardableResult works with try and try!, but not try? #71870

Open
@AnthonyLatsis

Description

@AnthonyLatsis

Description

No response

Reproduction

@discardableResult
func foo() throws -> Int {}

func test() {
  try? foo() // warning: result of 'try?' is unused [expression_unused_optional_try]
}

Expected behavior

No warning

Environment

Swift version 5.11-dev (Swift 11ef6e5)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @discardableResultFeature → attributes: The @discardableResult attributeattributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselferror handlingexpressionsFeature: expressionsswift 6.0type checkerArea → compiler: Semantic analysisunexpected warningBug: Unexpected warning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions