swiftlang/swift

[SR-9040] Suggestion when overriding implictly unwrapped optional does not suggest making parameter implictly unwrapped

Aperta

#51.543 aperta il 18 ott 2018

 (2 commenti) (0 reazioni) (0 assegnatari)Swift (10.719 fork)batch import
bugcompilerdiagnostics qualitygood first issue

Metriche repository

Star
 (69.989 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Previous ID SR-9040
Radar None
Original Reporter @JosephDuffy
Type Bug

Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0

Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 9b7c61d5cf17e72eb3e9d8e02cd54d9f

Issue Description:

When overriding a function that has an implicitly unwrapped optional parameter with a non-optional parameter, the fixit suggests adding ?, making the parameter optional.

I would expect this to offer adding !, along with ?, but I am not sure if this is classed as a bug, or an intentional change due to SE-0054.

Example code that produces the fixit:

class Foo {
    func bar(_ bar: String!) {}
}

class FooSubclass: Foo {
    override func bar(_ bar: String) {}
}

This produces the message: Cannot override instance method parameter of type 'String?' with non-optional type 'String', with an Insert '?' fix.

If this is classed as a bug I'd love to attempt to fix it![]( (if it's not, sorry))

Guida contributor