Skip to content

Commit 4fd4c00

Browse files
committed
[AST] ASTPrinter: Always print attributes after parameter specifiers
1 parent e302d73 commit 4fd4c00

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
@@ -3856,13 +3856,6 @@ static void printParameterFlags(ASTPrinter &printer,
38563856
printer.printKeyword("nonisolated(nonsending)", options, " ");
38573857
}
38583858

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

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

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

test/ModuleInterface/attrs.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ public enum TestExtensible {
100100
case a
101101
case b
102102
}
103+
104+
public struct TestPlacementOfAttrsAndSpecifiers {
105+
// CHECK: public func test1<T>(_: sending @autoclosure () -> T)
106+
public func test1<T>(_: sending @autoclosure () -> T) {}
107+
// CHECK: public func test2<T>(_: borrowing @autoclosure () -> T)
108+
public func test2<T>(_: borrowing @autoclosure () -> T) {}
109+
// CHECK: public func test3<T>(_: inout () async -> T)
110+
public func test3<T>(_: inout () async -> T) {}
111+
}

0 commit comments

Comments
 (0)