Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9040

Suggestion when overriding implictly unwrapped optional does not suggest making parameter implictly unwrapped

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Environment:

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

      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!)

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            josephduffy Joseph Duffy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: