File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -915,12 +915,21 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
915
915
// Give a note and fix-it
916
916
auto note = emitDiagnosticAt (PD, diag::noescape_parameter, PD->getName ());
917
917
918
+ SourceLoc reprLoc;
919
+ SourceLoc autoclosureEndLoc;
920
+ if (auto *repr = PD->getTypeRepr ()) {
921
+ reprLoc = repr->getStartLoc ();
922
+ if (auto *attrRepr = dyn_cast<AttributedTypeRepr>(repr)) {
923
+ autoclosureEndLoc = Lexer::getLocForEndOfToken (
924
+ getASTContext ().SourceMgr ,
925
+ attrRepr->getAttrs ().getLoc (TAK_autoclosure));
926
+ }
927
+ }
918
928
if (!PD->isAutoClosure ()) {
919
- SourceLoc reprLoc;
920
- if (auto *repr = PD->getTypeRepr ())
921
- reprLoc = repr->getStartLoc ();
922
929
note.fixItInsert (reprLoc, " @escaping " );
923
- } // TODO: add in a fixit for autoclosure
930
+ } else {
931
+ note.fixItInsertAfter (autoclosureEndLoc, " @escaping" );
932
+ }
924
933
925
934
return true ;
926
935
}
Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ struct StoresClosure {
44
44
return [ " ultimate answer " : fn] // expected-error{{using non-escaping parameter 'fn' in a context expecting an @escaping closure}}
45
45
}
46
46
47
+ func autoclosureDictPack( _ fn: @autoclosure ( ) -> Int ) -> [ String : ( ) -> Int ] {
48
+ // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{46-46= @escaping}}
49
+ return [ " ultimate answer " : fn] // expected-error{{using non-escaping parameter 'fn' in a context expecting an @escaping closure}}
50
+ }
51
+
47
52
func arrayPack( _ fn: @escaping ( ) -> Int , _ fn2 : ( ) -> Int ) -> [ ( ) -> Int ] {
48
53
// expected-note@-1{{parameter 'fn2' is implicitly non-escaping}} {{53-53=@escaping }}
49
54
You can’t perform that action at this time.
0 commit comments