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

Incorrect Code Coverage for Optional Binding with Else Statement

    XMLWordPrintable

    Details

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

      Xcode 7.2 (7C68), Mac OS X 10.11.1 (15B42)

      Description

      When testing code that involves an optional binding statement and an else statement, the swift compiler (or at least Xcode) reports that a statement, that should not be reachable, is not covered.

      Example to reproduce:

      func testFunction(input: String?) -> String? {
          if let input = input {
              return input
          } else {
              return input
          }
      }
      

      When testing the code above by calling it twice, once with a string instance and once with nil, code coverage will indicate that a statement after the else statement is untested (see attached screenshot).

      You can find the full example project on GitHub: https://github.com/Ben-G/AppleBugProjects/tree/master/CodeCoverageIssue.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            Ben-G Benjamin Encz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: