Skip to content

Commit 98ce87c

Browse files
authored
Merge pull request #80345 from hamishknight/nonisolated-range
A couple of SourceRange fixes for `nonisolated`
2 parents ecc9093 + 42e554e commit 98ce87c

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

include/swift/AST/Attr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3841,7 +3841,9 @@ class AtTypeAttrBase : public TypeAttribute {
38413841

38423842
SourceLoc getAtLoc() const { return AtLoc; }
38433843

3844-
SourceLoc getStartLocImpl() const { return AtLoc; }
3844+
SourceLoc getStartLocImpl() const {
3845+
return AtLoc.isValid() ? AtLoc : getAttrLoc();
3846+
}
38453847
SourceLoc getEndLocImpl() const { return getAttrLoc(); }
38463848
};
38473849

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ ERROR(class_cannot_be_addressable_for_dependencies,none,
319319
"a class cannot be @_addressableForDependencies", ())
320320

321321
ERROR(unsupported_closure_attr,none,
322-
"%select{attribute |}0 '%1' is not supported on a closure",
322+
"%select{attribute |}0'%1' is not supported on a closure",
323323
(bool, StringRef))
324324

325325
NOTE(suggest_partial_overloads,none,

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,6 +3741,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
37413741
break;
37423742
}
37433743
case DeclAttrKind::Nonisolated: {
3744+
AttrRange = Loc;
37443745
std::optional<bool> isUnsafe(false);
37453746
if (EnableParameterizedNonisolated) {
37463747
isUnsafe =

test/Concurrency/nonisolated_rules.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ struct UnsafeInitialization {
177177
self.ns = ns // okay
178178
}
179179
}
180+
181+
// rdar://147965036 - Make sure we don't crash.
182+
func rdar147965036() {
183+
func test(_: () -> Void) {}
184+
test { @nonisolated in
185+
// expected-error@-1 {{'nonisolated' is a declaration modifier, not an attribute}}
186+
// expected-error@-2 {{'nonisolated' is not supported on a closure}}
187+
}
188+
}

0 commit comments

Comments
 (0)