Files
swift-mirror/test/Constraints/rdar107420031.swift
Hamish Knight da86703e2a [CS] Fix coercePatternToType enum cast handling
Previously if the cast was unresolved, we would
emit a warning and bail with `nullptr`. This is
wrong, because the caller expects a `nullptr`
return to mean we emitted an error. Change the
diagnostic to an error to fix this. This may
appear source breaking, but in reality previously
we were failing to add the cast at all in this case,
which lead to a crash in SILGen. We really do
want to reject these cases as errors, as this
will give us a better opportunity to fall back to
type-checking as ExprPatterns, and better matches
the constraint solver type-checking.

Also while we're here, change the diagnostic for
the case where we don't have an existential context
type from the confusing "enum doesn't have member"
diagnostic to the pattern mismatch diagnostic.

rdar://107420031
2023-06-07 00:35:02 +01:00

19 lines
358 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// RUN: %target-typecheck-verify-swift
enum E {
case e
}
func ~= (lhs: any Error, rhs: E) -> Bool { true }
// rdar://107420031 Make sure we don't crash.
// TODO: This ought to compile.
func foo(_ error: any Error) {
switch error {
case E.e: // expected-error {{pattern of type 'E' cannot match 'any Error'}}
break
default:
break
}
}