Skip to content

Commit 28d3c6c

Browse files
Addressing CR comments
1 parent 5defa1f commit 28d3c6c

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ ERROR(autoclosure_function_type,none,
26822682
())
26832683

26842684
ERROR(invalid_autoclosure_and_convention_attributes,none,
2685-
"@convention(%0) attribute is not allowed on @autoclosure type",
2685+
"'@convention(%0)' attribute is not allowed on '@autoclosure' types",
26862686
(StringRef))
26872687

26882688
ERROR(autoclosure_function_input_nonunit,none,

lib/Sema/TypeCheckType.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,16 +2256,18 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
22562256
attrs.getConvention());
22572257
rep = FunctionType::Representation::Swift;
22582258
} else {
2259-
auto convention = attrs.getConvention();
2259+
rep = *parsedRep;
2260+
22602261
if (attrs.has(TAK_autoclosure)) {
22612262
// @convention(c) and @convention(block) are not allowed with an @autoclosure type.
2262-
if (convention == "c" || convention == "block" ) {
2263+
if (rep == FunctionType::Representation::CFunctionPointer ||
2264+
rep == FunctionType::Representation::Block) {
22632265
diagnose(attrs.getLoc(TAK_convention),
22642266
diag::invalid_autoclosure_and_convention_attributes,
22652267
attrs.getConvention());
2268+
attrs.clearAttribute(TAK_autoclosure);
22662269
}
22672270
}
2268-
rep = *parsedRep;
22692271
}
22702272
}
22712273

test/attr/attr_convention.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ let f5: @convention(INTERCAL) (Int) -> Int = { $0 } // expected-error{{conventio
99

1010
// SR-11027
1111

12-
func sr11027(_ f: @convention(block) @autoclosure () -> Int) -> Void {} // expected-error {{@convention(block) attribute is not allowed on @autoclosure type}}
12+
func sr11027(_ f: @convention(block) @autoclosure () -> Int) -> Void {} // expected-error {{'@convention(block)' attribute is not allowed on '@autoclosure' types}}
1313
sr11027(1)
1414

15-
func sr11027_c(_ f: @convention(c) @autoclosure () -> Int) -> Void {} // expected-error{{@convention(c) attribute is not allowed on @autoclosure type}}
15+
func sr11027_c(_ f: @convention(c) @autoclosure () -> Int) -> Void {} // expected-error{{'@convention(c)' attribute is not allowed on '@autoclosure' types}}
1616
sr11027_c(1)
1717

1818
func sr11027_swift(_ f: @convention(swift) @autoclosure () -> Int) -> Void {} // OK
1919
sr11027_swift(1)
2020

2121
func sr11027_thin(_ f: @convention(thin) @autoclosure () -> Int) -> Void {} // OK
2222
sr11027_thin(1)
23+
24+
func sr11027_2(_ f: @autoclosure @convention(block) () -> Int) -> Void {} // expected-error {{'@convention(block)' attribute is not allowed on '@autoclosure' types}}
25+
sr11027_2(1)
26+
27+
func sr11027_c_2(_ f: @autoclosure @convention(c) () -> Int) -> Void {} // expected-error {{'@convention(c)' attribute is not allowed on '@autoclosure' types}}
28+
sr11027_c_2(1)
29+
30+
func sr11027_swift_2(_ f: @autoclosure @convention(swift) () -> Int) -> Void {} // OK
31+
sr11027_swift_2(1)
32+
33+
func sr11027_thin_2(_ f: @autoclosure @convention(thin) () -> Int) -> Void {} // OK
34+
sr11027_thin_2(1)

validation-test/compiler_crashers_2_fixed/sr11027.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ sr11027_swift(1)
1818

1919
func sr11027_thin(_ f: @convention(thin) @autoclosure () -> Int) -> Void {} // OK
2020
sr11027_thin(1)
21+
22+
func sr11027_2(_ f: @autoclosure @convention(block) () -> Int) -> Void {}
23+
sr11027_2(1)
24+
25+
func sr11027_c_2(_ f: @autoclosure @convention(c) () -> Int) -> Void {}
26+
sr11027_c_2(1)
27+
28+
func sr11027_swift_2(_ f: @autoclosure @convention(swift) () -> Int) -> Void {} // OK
29+
sr11027_swift_2(1)
30+
31+
func sr11027_thin_2(_ f: @autoclosure @convention(thin) () -> Int) -> Void {} // OK
32+
sr11027_thin_2(1)

0 commit comments

Comments
 (0)