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

Code after `return`, inconsistent diagnostics and behavior

    XMLWordPrintable

    Details

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

      Description

      The following program runs and prints a series of numbers, so either the warning is misleading or the behavior is not as intended.

      func foo() -> Int {
      
        return _E.bar
      
        struct _E { // WARNING: Code after 'return' will never be executed
          private static var count = 0
          static var bar: Int {
            count += (Bool.random() ? foo() : 1)
            return count
          }
        }
      }
      
      for _ in 0 ..< 7 { print(foo()) }
      

      Related thread (with more similar examples):
      https://forums.swift.org/t/should-this-misleading-warning-be-here/40678

        Attachments

          Activity

            People

            Assignee:
            guitardog Josh Learn
            Reporter:
            jens Jens Persson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: