Bug SR-2022 suggests improving the error message for using as?
in a case/let where a plain as
(no question mark) should have been used.
The current the errors are
switch myVariable {
case let n as? Float:
...
SR-2022.swift:13:13: warning: cast from '_' to unrelated type 'Float' always fails
case let n as? Float:
~ ^ ~~~~~
SR-2022.swift:13:13: warning: cast from '_' to unrelated type 'Float' always fails
case let n as? Float:
~ ^ ~~~~~
SR-2022.swift:13:13: error: expression pattern of type 'Float?' cannot match values of type 'Any'
case let n as? Float:
~~^~~~~~~~~
The fix is to remove the question mark, which is not suggested.
So there is room for improvement here.
My question for everyone here is: what should the error message be?
- 'as?' cannot appear in switch pattern bindings!
- Lose the question mark meatbag.
- 'as' in 'case' statement dose not use '?'
- don't use as?!
- something else?