-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfpattern matchingFeature: pattern matchingFeature: pattern matchingpatternsFeature: patternsFeature: patternsswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
Description
Steps To Reproduce
For example, this code snippet
protocol T {}
struct A: T {}
func test_switch<T>(arr: T) {
if case _ as A = arr {}
}should work fine. However, it gives the following error:
error: cannot convert value of type 'T' to specified type 'A'
if case _ as A = arr {}
^~~
as! A
and emits non-relevant diagnostics.
Expected behavior
Even though this works by binding the result of the cast to a constant (if case let t as A = arr {}), the case specified above should also work.
Environment (please fill out the following information)
- OS: macOS 12.5.1
- Swift version: 5.8-dev
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfpattern matchingFeature: pattern matchingFeature: pattern matchingpatternsFeature: patternsFeature: patternsswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error