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-10105] @discardableResult from protocol is not applied when optionals introduced #52507

Closed
swift-ci opened this issue Mar 14, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10105
Radar None
Original Reporter basememara (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 0de5b9a4ccfa7d8aa896b8c8c9e607e2

duplicates:

Issue Description:

It seems @discardableResult on protocols get ignored when one of the pieces are optional:

protocol Bar {
    
}


class BarImpl: Bar {
    
}


extension Bar where Self: BarImpl {
    
    @discardableResult
    func foo1() -> Int {
        return 1
    }
    
    @discardableResult
    func foo2() -> Int? {
        return 2
    }
}


struct TestWrapper {
    private let object: (Bar & BarImpl)?
    
    init(object: (Bar & BarImpl)) {
        self.object = object
    }
    
    func test() {
        object?.foo1() // No warning
        object?.foo2() // Expression of type 'Int?' is unused
    }
}

When I remove the optional from `(Bar & BarImpl)?` or `func foo2() -> Int?`, the warning goes away.

@belkadan
Copy link
Contributor

cc @xedin

@theblixguy
Copy link
Collaborator

This no longer diagnoses in 5.1 (also, this looks like a dupe of SR-9646). The problem was that checkIgnoredExpr() wasn't looking though OpenExistentialExpr, which I fixed.

@belkadan
Copy link
Contributor

Aha, I should have done a better search. Thanks, Suyash!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants