Skip to content

Commit ee38182

Browse files
committed
[AST] ASTPrinter: Don't print '@escaping' on 'inout' parameters
All of the `inout` types are implicitly `@escaping`.
1 parent 6662a48 commit ee38182

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,8 +3908,11 @@ static void printParameterFlags(ASTPrinter &printer,
39083908
printer.printKeyword("isolated", options, " ");
39093909
}
39103910

3911-
if (!options.excludeAttrKind(TypeAttrKind::Escaping) && escaping)
3912-
printer.printKeyword("@escaping", options, " ");
3911+
// `inout` implies `@escaping`
3912+
if (flags.getOwnershipSpecifier() != ParamSpecifier::InOut) {
3913+
if (!options.excludeAttrKind(TypeAttrKind::Escaping) && escaping)
3914+
printer.printKeyword("@escaping", options, " ");
3915+
}
39133916

39143917
if (flags.isCompileTimeLiteral())
39153918
printer.printKeyword("_const", options, " ");

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ func rdar17170728() {
11271127
}
11281128

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

test/ModuleInterface/execution_behavior_attrs.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public struct TestWithAttrs {
1010
// CHECK-NEXT: public func test(_: nonisolated(nonsending) @escaping () async -> Swift.Void)
1111
// CHECK-NEXT: #endif
1212
public func test(_: nonisolated(nonsending) @escaping () async -> Void) {}
13+
14+
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
15+
// CHECK-NEXT: public func withInOut(fn: nonisolated(nonsending) inout () async -> Swift.Void)
16+
// CHECK-NEXT: #endif
17+
public func withInOut(fn: nonisolated(nonsending) inout () async -> Void) {}
1318
}
1419

1520
public struct Test {

0 commit comments

Comments
 (0)