Record throwing property accesses as potential throw sites

This commit is contained in:
Doug Gregor
2023-12-13 16:36:14 -08:00
parent 956c330611
commit ae5f66ac11
4 changed files with 91 additions and 23 deletions

View File

@@ -196,12 +196,24 @@ struct ThrowingMembers {
subscript(i: Int) -> Int {
get throws(MyError) { i }
}
var intOrThrows: Int {
get throws(MyError) { 5 }
}
}
struct ThrowingStaticSubscript {
static subscript(i: Int) -> Int {
get throws(MyError) { i }
}
static var intOrThrows: Int {
get throws(MyError) { 5 }
}
}
var globalIntOrThrows: Int {
get throws(MyError) { 5 }
}
func testDoCatchInClosure(cond: Bool, x: ThrowingMembers) {
@@ -262,4 +274,29 @@ func testDoCatchInClosure(cond: Bool, x: ThrowingMembers) {
let _: MyError = error
}
}
// Property accesses as potential throw sites
apply {
do {
_ = try x.intOrThrows
} catch {
let _: MyError = error
}
}
apply {
do {
_ = try ThrowingStaticSubscript.intOrThrows
} catch {
let _: MyError = error
}
}
apply {
do {
_ = try globalIntOrThrows
} catch {
let _: MyError = error
}
}
}