File tree 3 files changed +38
-3
lines changed
3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ extension Parser {
157
157
shouldParseArgument = true
158
158
case . customAttribute:
159
159
shouldParseArgument =
160
- self . withLookahead { $0. atCustomAttributeArgument ( ) }
160
+ self . withLookahead { $0. atAttributeOrSpecifierArgument ( ) }
161
161
&& self . at ( TokenSpec ( . leftParen, allowAtStartOfLine: false ) )
162
162
case . optional:
163
163
shouldParseArgument = self . at ( . leftParen)
@@ -1002,7 +1002,7 @@ extension Parser {
1002
1002
// MARK: Lookahead
1003
1003
1004
1004
extension Parser . Lookahead {
1005
- mutating func atCustomAttributeArgument ( ) -> Bool {
1005
+ mutating func atAttributeOrSpecifierArgument ( ) -> Bool {
1006
1006
var lookahead = self . lookahead ( )
1007
1007
lookahead. skipSingle ( )
1008
1008
@@ -1036,7 +1036,7 @@ extension Parser.Lookahead {
1036
1036
}
1037
1037
1038
1038
if self . at ( TokenSpec ( . leftParen, allowAtStartOfLine: false ) )
1039
- && self . withLookahead ( { $0. atCustomAttributeArgument ( ) } )
1039
+ && self . withLookahead ( { $0. atAttributeOrSpecifierArgument ( ) } )
1040
1040
{
1041
1041
self . skipSingle ( )
1042
1042
}
Original file line number Diff line number Diff line change @@ -1059,6 +1059,27 @@ extension Parser {
1059
1059
private mutating func parseNonisolatedTypeSpecifier( ) -> RawTypeSpecifierListSyntax . Element {
1060
1060
let ( unexpectedBeforeNonisolatedKeyword, nonisolatedKeyword) = self . expect ( . keyword( . nonisolated) )
1061
1061
1062
+ // Avoid being to greedy about `(` since this modifier should be associated with
1063
+ // function types, it's possible that the argument is omitted and what follows
1064
+ // is a function type i.e. `nonisolated () async -> Void`.
1065
+ if self . at ( . leftParen) && !withLookahead( { $0. atAttributeOrSpecifierArgument ( ) } ) {
1066
+ let argument = RawNonisolatedSpecifierArgumentSyntax (
1067
+ leftParen: missingToken ( . leftParen) ,
1068
+ nonsendingKeyword: missingToken ( . keyword( . nonsending) ) ,
1069
+ rightParen: missingToken ( . rightParen) ,
1070
+ arena: self . arena
1071
+ )
1072
+
1073
+ let nonisolatedSpecifier = RawNonisolatedTypeSpecifierSyntax (
1074
+ unexpectedBeforeNonisolatedKeyword,
1075
+ nonisolatedKeyword: nonisolatedKeyword,
1076
+ argument: argument,
1077
+ arena: self . arena
1078
+ )
1079
+ return . nonisolatedTypeSpecifier( nonisolatedSpecifier)
1080
+ }
1081
+
1082
+ // nonisolated without an argument is valid in some positions i.e. inheritance clause.
1062
1083
guard let leftParen = self . consume ( if: . leftParen) else {
1063
1084
let nonisolatedSpecifier = RawNonisolatedTypeSpecifierSyntax (
1064
1085
unexpectedBeforeNonisolatedKeyword,
Original file line number Diff line number Diff line change @@ -546,10 +546,23 @@ final class TypeTests: ParserTestCase {
546
546
assertParse ( " func foo(test: nonisolated(nonsending) () async -> Void) " )
547
547
assertParse ( " func foo(test: nonisolated(nonsending) @escaping () async -> Void) {} " )
548
548
549
+ assertParse (
550
+ " func foo(test: nonisolated1️⃣ () async -> Void) " ,
551
+ diagnostics: [
552
+ DiagnosticSpec (
553
+ locationMarker: " 1️⃣ " ,
554
+ message: " expected '(nonsending)' in 'nonisolated' specifier " ,
555
+ fixIts: [ " insert '(nonsending)' " ]
556
+ )
557
+ ] ,
558
+ fixedSource: " func foo(test: nonisolated(nonsending) () async -> Void) "
559
+ )
560
+
549
561
assertParse (
550
562
" func foo(test: nonisolated(1️⃣) () async -> Void) " ,
551
563
diagnostics: [
552
564
DiagnosticSpec (
565
+ locationMarker: " 1️⃣ " ,
553
566
message: " expected 'nonsending' in 'nonisolated' specifier " ,
554
567
fixIts: [ " insert 'nonsending' " ]
555
568
)
@@ -561,6 +574,7 @@ final class TypeTests: ParserTestCase {
561
574
" func foo(test: nonisolated(1️⃣hello) () async -> Void) " ,
562
575
diagnostics: [
563
576
DiagnosticSpec (
577
+ locationMarker: " 1️⃣ " ,
564
578
message: " expected 'nonsending' in 'nonisolated' specifier " ,
565
579
fixIts: [ " insert 'nonsending' " ]
566
580
) ,
You can’t perform that action at this time.
0 commit comments