SE-0458: Disambiguate postfix expressions vs. unsafe expressions more generally

Handle call-vs-tuple and subscript-vs-collection-expr disambiguation using the
same "no trivia" rule that we used to disambiguite "unsafe.x" (which we
treat as a member access) from "unsafe .x" (which we treat as an unsafe
expression with a leading-dot member access).

Fixes rdar://146459104.
This commit is contained in:
Doug Gregor
2025-03-07 10:17:45 -08:00
parent 80050bb455
commit 6cf56e9eb7
2 changed files with 19 additions and 1 deletions

View File

@@ -183,6 +183,8 @@ func acceptBools(_: Bool, _: Bool) { }
func acceptBoolsUnsafeLabel(unsafe _: Bool, _: Bool) { }
func unsafe(_: Int) { }
func unsafeFun() {
var unsafe = true
unsafe = false
@@ -200,6 +202,20 @@ func unsafeFun() {
if unsafe { }
}
func moreUnsafeFunc(unsafe: [Int]) {
let _: [Int] = unsafe []
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}
_ = unsafe[1]
}
func yetMoreUnsafeFunc(unsafe: () -> Void) {
unsafe()
_ = unsafe ()
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}
}
// @safe suppresses unsafe-type-related diagnostics on an entity
struct MyArray<Element> {
@safe func withUnsafeBufferPointer<R, E>(