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

Unused result warning phrasing is worse for closures than normal functions

    XMLWordPrintable

    Details

      Description

      func foo() -> Int { return 0 }
      foo()
      
      let f: () -> Int = foo
      f()
      
      func bar(g: () -> Int) { g() }
      

      Gives:

      rdar26661027.swift:2:1: warning: result of call to 'foo()' is unused
      foo()
      ^  ~~
      rdar26661027.swift:5:1: warning: result of call is unused, but produces 'Int'
      f()
      ^~~
      rdar26661027.swift:8:26: warning: result of call is unused, but produces 'Int'
      func bar(g: () -> Int) { g() }
                               ^~~
      

      The "but produces ..." addition is a bit awkward. This typing information doesn't seem particularly important, although maybe for closures it is harder to work out what the type actually is?

      In any case, maybe the message for the expression_unused_result_unknown WARNING in include/swift/AST/DiagnosticsSema.def could be wordsmithed a bit, e.g. result of call to function returning '%0' is unused.

        Attachments

          Activity

            People

            Assignee:
            anthonylatsis Anthony Latsis
            Reporter:
            huon Huon Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: