[Sema] Ban placeholders in typed throws

This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
This commit is contained in:
Hamish Knight
2025-09-17 15:23:08 +01:00
parent 71f8e68655
commit 9f5a754b77
5 changed files with 29 additions and 5 deletions

View File

@@ -12,6 +12,8 @@ case dogAteIt
case forgot
}
struct GenericError<T>: Error {}
func processMyError(_: MyError) { }
func doSomething() throws(MyError) { }
@@ -418,3 +420,12 @@ func testSequenceExpr() async throws(Never) {
try true ? 0 : try! getInt() ~~~ getInt()
// expected-error@-1 {{'try!' following conditional operator does not cover everything to its right}}
}
func testPlaceholder() {
do throws(_) {} catch {}
// expected-error@-1 {{type placeholder not allowed here}}
// expected-warning@-2 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
do throws(GenericError<_>) {} catch {}
// expected-error@-1 {{type placeholder not allowed here}}
// expected-warning@-2 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
}