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

spurious "unused result" warning in Swift 3

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Environment:

      Xcode 7.3.1, Toolchain: Swift Development Snapshot 2016-05-31 (a)

      Description

      Consider the following code:

      class ViewController: UIViewController {
          func test() {
              // no warning
              self.navigationController?.pushViewController(UIViewController(), animated:false)
              // warning
              self.navigationController?.popViewController(animated:false)
          }
      }
      

      The first line causes no warning. The second line causes a warning, "Expression of type 'UIViewController?' is unused."

      Of course I understand why this is, in theory. The second call returns a value, and I am ignoring it. But from a practical point of view, to ignore this value is normal behavior, so the warning is just annoying (i.e. it isn't helpful). I can work around the problem by assigning the second line to an unnamed variable:

              _ = self.navigationController?.popViewController(animated:false)
      

      But this seems like a bit much. I'm ending up with my code peppered with that sort of expression; it's kind of ugly.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                timbodeit Tim Bodeit
                Reporter:
                mattneub Matt Neuburg
              • Votes:
                3 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: