Skip to content

Commit fbadca2

Browse files
committed
[AST] ASTPrinter: Always print attributes after parameter specifiers
(cherry picked from commit 4fd4c00)
1 parent 3bb3a07 commit fbadca2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,13 +3855,6 @@ static void printParameterFlags(ASTPrinter &printer,
38553855
printer.printKeyword("nonisolated(nonsending)", options, " ");
38563856
}
38573857

3858-
if (!options.excludeAttrKind(TypeAttrKind::Autoclosure) &&
3859-
flags.isAutoClosure())
3860-
printer.printAttrName("@autoclosure ");
3861-
if (!options.excludeAttrKind(TypeAttrKind::NoDerivative) &&
3862-
flags.isNoDerivative())
3863-
printer.printAttrName("@noDerivative ");
3864-
38653858
switch (flags.getOwnershipSpecifier()) {
38663859
case ParamSpecifier::Default:
38673860
/*nothing*/
@@ -3907,15 +3900,22 @@ static void printParameterFlags(ASTPrinter &printer,
39073900
printer.printKeyword("isolated", options, " ");
39083901
}
39093902

3903+
if (flags.isCompileTimeLiteral())
3904+
printer.printKeyword("_const", options, " ");
3905+
3906+
if (!options.excludeAttrKind(TypeAttrKind::Autoclosure) &&
3907+
flags.isAutoClosure())
3908+
printer.printAttrName("@autoclosure ");
3909+
if (!options.excludeAttrKind(TypeAttrKind::NoDerivative) &&
3910+
flags.isNoDerivative())
3911+
printer.printAttrName("@noDerivative ");
3912+
39103913
// `inout` implies `@escaping`
39113914
if (flags.getOwnershipSpecifier() != ParamSpecifier::InOut) {
39123915
if (!options.excludeAttrKind(TypeAttrKind::Escaping) && escaping)
39133916
printer.printAttrName("@escaping ");
39143917
}
39153918

3916-
if (flags.isCompileTimeLiteral())
3917-
printer.printKeyword("_const", options, " ");
3918-
39193919
if (flags.isConstValue())
39203920
printer.printAttrName("@const ");
39213921
}

test/ModuleInterface/attrs.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,12 @@ public func testExecutionConcurrent() async {}
9292
nonisolated(nonsending)
9393
public func testExecutionCaller() async {}
9494
// CHECK: nonisolated(nonsending) public func testExecutionCaller() async
95+
96+
public struct TestPlacementOfAttrsAndSpecifiers {
97+
// CHECK: public func test1<T>(_: sending @autoclosure () -> T)
98+
public func test1<T>(_: sending @autoclosure () -> T) {}
99+
// CHECK: public func test2<T>(_: borrowing @autoclosure () -> T)
100+
public func test2<T>(_: borrowing @autoclosure () -> T) {}
101+
// CHECK: public func test3<T>(_: inout () async -> T)
102+
public func test3<T>(_: inout () async -> T) {}
103+
}

0 commit comments

Comments
 (0)