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

Availability of enum case does not propagate to its switch case scope.

    XMLWordPrintable

    Details

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

      Xcode 8.2.1 (8C1002)

      Description

      When matching against a case with minimum API requirement, the scope logically inherits the requirement from the case. But the compiler currently does not propagate the requirement, and requires a fallback to dynamic `#available` checks.

      import MachO
      
      enum Lock {
      	@available(macOS 10.12, *)
      	case unfairLock(os_unfair_lock_t)
      
      	func lock() {
      		switch self {
      		case let .unfairLock(lock):
      			// Unreachable in macOS version <10.12, but
      			// `#available` is still required here for a green light
      			// from the compiler.
      			os_unfair_lock_lock(lock)
      		}
      	}
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              andersha Anders Ha
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: