[AST] ASTPrinter: Don't print '@escaping' on 'inout' parameters

All of the `inout` types are implicitly `@escaping`.
This commit is contained in:
Pavel Yaskevich
2025-04-15 15:02:54 -07:00
parent 6662a48533
commit ee38182ae2
3 changed files with 11 additions and 3 deletions

View File

@@ -3908,8 +3908,11 @@ static void printParameterFlags(ASTPrinter &printer,
printer.printKeyword("isolated", options, " ");
}
if (!options.excludeAttrKind(TypeAttrKind::Escaping) && escaping)
printer.printKeyword("@escaping", options, " ");
// `inout` implies `@escaping`
if (flags.getOwnershipSpecifier() != ParamSpecifier::InOut) {
if (!options.excludeAttrKind(TypeAttrKind::Escaping) && escaping)
printer.printKeyword("@escaping", options, " ");
}
if (flags.isCompileTimeLiteral())
printer.printKeyword("_const", options, " ");

View File

@@ -1127,7 +1127,7 @@ func rdar17170728() {
}
let _ = [i, j, k].reduce(0 as Int?) { // expected-error {{missing argument label 'into:' in call}}
// expected-error@-1 {{cannot convert value of type 'Int?' to expected argument type '(inout @escaping (Bool, Bool) -> Bool?, Int?) throws -> ()'}}
// expected-error@-1 {{cannot convert value of type 'Int?' to expected argument type '(inout (Bool, Bool) -> Bool?, Int?) throws -> ()'}}
$0 && $1 ? $0 + $1 : ($0 ? $0 : ($1 ? $1 : nil))
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
}

View File

@@ -10,6 +10,11 @@ public struct TestWithAttrs {
// CHECK-NEXT: public func test(_: nonisolated(nonsending) @escaping () async -> Swift.Void)
// CHECK-NEXT: #endif
public func test(_: nonisolated(nonsending) @escaping () async -> Void) {}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: public func withInOut(fn: nonisolated(nonsending) inout () async -> Swift.Void)
// CHECK-NEXT: #endif
public func withInOut(fn: nonisolated(nonsending) inout () async -> Void) {}
}
public struct Test {