mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This is a new feature of Swift 5 mode, so it deserves at least a
little bit of explanation right in the diagnostic. If you have an
otherwise-fully-covered switch but can't assume the enum is frozen,
you'll now get this message:
switch covers known cases, but 'MusicGenre' may have additional
unknown values
Furthermore, if the enum comes from a system header, it looks like
this:
switch covers known cases, but 'NSMusicGenre' may have additional
unknown values, possibly added in future versions
...to further suggest the idea that even though your switch is covered
/now/, it might not handle everything in the /future/. This extra bit
is limited to system headers to avoid showing up on C enums defined in
your own project, for which it sounds silly. (The main message is
still valid though, since you can cram whatever you want into a C
enum, and people use this pattern to implement "private cases".)
rdar://problem/39367045
32 lines
1.7 KiB
Swift
32 lines
1.7 KiB
Swift
// RUN: %target-swift-frontend -emit-sil %s -enable-objc-interop -import-objc-header %S/Inputs/enum-objc.h -verify -enable-nonfrozen-enum-exhaustivity-diagnostics
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
func test(_ value: SwiftEnum, _ exhaustiveValue: ExhaustiveEnum) {
|
|
switch value { // expected-warning {{switch covers known cases, but 'SwiftEnum' may have additional unknown values}} expected-note {{handle unknown values using "@unknown default"}}
|
|
case .one: break
|
|
case .two: break
|
|
case .three: break
|
|
}
|
|
|
|
switch exhaustiveValue { // ok
|
|
case .one: break
|
|
case .two: break
|
|
case .three: break
|
|
}
|
|
}
|
|
|
|
let _: Int = forwardBarePointer // expected-error {{cannot convert value of type '(OpaquePointer) -> Void' to specified type 'Int'}}
|
|
let _: Int = forwardWithUnderlyingPointer // expected-error {{cannot convert value of type '(OpaquePointer) -> Void' to specified type 'Int'}}
|
|
let _: Int = forwardObjCPointer // expected-error {{cannot convert value of type '(OpaquePointer) -> Void' to specified type 'Int'}}
|
|
|
|
// FIXME: It would be nice to import these as unavailable somehow instead.
|
|
let _: Int = forwardWithUnderlyingValue // expected-error {{use of unresolved identifier 'forwardWithUnderlyingValue'}}
|
|
let _: Int = forwardObjCValue // expected-error {{use of unresolved identifier 'forwardObjCValue'}}
|
|
|
|
// Note that if /these/ start getting imported as unavailable, the error will
|
|
// also mention that there's a missing argument, since the second argument isn't
|
|
// actually defaultable.
|
|
_ = SomeClass.tryInferDefaultArgumentUnderlyingValue(false) // expected-error {{type 'SomeClass' has no member 'tryInferDefaultArgumentUnderlyingValue'}}
|
|
_ = SomeClass.tryInferDefaultArgumentObjCValue(false) // expected-error {{type 'SomeClass' has no member 'tryInferDefaultArgumentObjCValue'}}
|