Skip to content

[SR-7562] @discardableResult is disregarded for a required init method #50104

@swift-ci

Description

@swift-ci
Previous ID SR-7562
Radar None
Original Reporter Vandad (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

swift --version

Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)

Target: x86_64-apple-darwin17.5.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee @vguerra
Priority Medium

md5: bddad59f549a8118d77ef9d4bf5040fb

Issue Description:

My problem is sort of related to the following issue: SR-2198

Consider the following example:

protocol HasInitMethod {
    associatedtype Input
    init(input: Input)
}

class Foo<Input>: HasInitMethod {
    @discardableResult required init(input: Input) {
        //empty for now
    }
}

class Bar: Foo<Int> {
}

If I instantiate Foo, with its init method marked with @discardableResult, then the compiler does a good job of not warning me about the unused result.

However, if I instantiate Bar, who inherits its init method from Foo, I will get a warning:

Foo(input :10) //no warnings, nice!
Bar(input: 10) //warning: Result of 'Bar' initializer is unused

I believe this to be a bug and not a feature since Bar can and should inherit its init method from Foo to be able to get the same effect as Foo has.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions