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

Incorrect fixit for logical NOT operator on value of Bool? type 

    XMLWordPrintable

    Details

      Description

      The following code prompts an error that states "Value of optional type 'Bool?' must be unwrapped to a value of type 'Bool'"

      let optionalBool: Bool? = false
      if !optionalBool { }
      

      The fixit that says "Coalesce using '??' to provide a default when the optional value contains 'nil'" generates this:

      let optionalBool: Bool? = false
      if !optionalBool ?? <#default value#> { }

      This code prompts the same error. The appropriate correction would be:

      let optionalBool: Bool? = false
      if !(optionalBool ?? <#default value#>) { }
      

        Attachments

          Activity

            People

            Assignee:
            xcadaverx Daniel Williams
            Reporter:
            thompsonate Nate Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: