@@ -905,6 +905,115 @@ final class DeclarationTests: ParserTestCase {
905
905
""" ,
906
906
experimentalFeatures: [ . typedThrows]
907
907
)
908
+
909
+ assertParse (
910
+ " func test() throws(MyError) 1️⃣async {} " ,
911
+ diagnostics: [
912
+ DiagnosticSpec ( message: " 'async' must precede 'throws' " , fixIts: [ " move 'async' in front of 'throws' " ] )
913
+ ] ,
914
+ fixedSource: " func test() async throws(MyError) {} " ,
915
+ experimentalFeatures: [ . typedThrows]
916
+ )
917
+ assertParse (
918
+ " func test() throws 1️⃣async2️⃣(MyError) {} " ,
919
+ diagnostics: [
920
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " 'async' must precede 'throws' " , fixIts: [ " move 'async' in front of 'throws' " ] ) ,
921
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
922
+ ] ,
923
+ fixedSource: " func test() async throws (MyError) {} " ,
924
+ experimentalFeatures: [ . typedThrows]
925
+ )
926
+ assertParse (
927
+ " func test() 1️⃣try2️⃣(MyError) async {} " ,
928
+ diagnostics: [
929
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected throwing specifier; did you mean 'throws'? " , fixIts: [ " replace 'try' with 'throws' " ] ) ,
930
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError) async' in function " ) ,
931
+ ] ,
932
+ fixedSource: " func test() throws (MyError) async {} " ,
933
+ experimentalFeatures: [ . typedThrows]
934
+ )
935
+ assertParse (
936
+ " func test() 1️⃣try 2️⃣async3️⃣(MyError) {} " ,
937
+ diagnostics: [
938
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected throwing specifier; did you mean 'throws'? " , fixIts: [ " replace 'try' with 'throws' " ] ) ,
939
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " 'async' must precede 'throws' " , fixIts: [ " move 'async' in front of 'throws' " ] ) ,
940
+ DiagnosticSpec ( locationMarker: " 3️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
941
+ ] ,
942
+ fixedSource: " func test() async throws (MyError) {} " ,
943
+ experimentalFeatures: [ . typedThrows]
944
+ )
945
+ assertParse (
946
+ " func test() throws(MyError) 1️⃣await {} " ,
947
+ diagnostics: [
948
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " 'await' must precede 'throws' " , fixIts: [ " move 'await' in front of 'throws' " ] )
949
+ ] ,
950
+ fixedSource: " func test() async throws(MyError) {} " ,
951
+ experimentalFeatures: [ . typedThrows]
952
+ )
953
+ assertParse (
954
+ " func test() throws 1️⃣await2️⃣(MyError) {} " ,
955
+ diagnostics: [
956
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " 'await' must precede 'throws' " , fixIts: [ " move 'await' in front of 'throws' " ] ) ,
957
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
958
+ ] ,
959
+ fixedSource: " func test() async throws (MyError) {} " ,
960
+ experimentalFeatures: [ . typedThrows]
961
+ )
962
+ assertParse (
963
+ " func test() 1️⃣try2️⃣(MyError) await {} " ,
964
+ diagnostics: [
965
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected throwing specifier; did you mean 'throws'? " , fixIts: [ " replace 'try' with 'throws' " ] ) ,
966
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError) await' in function " ) ,
967
+ ] ,
968
+ fixedSource: " func test() throws (MyError) await {} " ,
969
+ experimentalFeatures: [ . typedThrows]
970
+ )
971
+ assertParse (
972
+ " func test() 1️⃣try await2️⃣(MyError) {} " ,
973
+ diagnostics: [
974
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected throwing specifier; did you mean 'throws'? " , fixIts: [ " replace 'try' with 'throws' " ] ) ,
975
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
976
+ ] ,
977
+ fixedSource: " func test() awaitthrows (MyError) {} " , // FIXME: spacing
978
+ experimentalFeatures: [ . typedThrows]
979
+ )
980
+ assertParse (
981
+ " func test() async1️⃣(MyError) {} " ,
982
+ diagnostics: [
983
+ DiagnosticSpec ( message: " unexpected code '(MyError)' in function " )
984
+ ] ,
985
+ experimentalFeatures: [ . typedThrows]
986
+ )
987
+ assertParse (
988
+ " func test() 1️⃣await2️⃣(MyError) {} " ,
989
+ diagnostics: [
990
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected async specifier; did you mean 'async'? " , fixIts: [ " replace 'await' with 'async' " ] ) ,
991
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
992
+ ] ,
993
+ fixedSource: " func test() async (MyError) {} " ,
994
+ experimentalFeatures: [ . typedThrows]
995
+ )
996
+ assertParse (
997
+ " func test() 1️⃣try2️⃣(MyError) {} " ,
998
+ diagnostics: [
999
+ DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " expected throwing specifier; did you mean 'throws'? " , fixIts: [ " replace 'try' with 'throws' " ] ) ,
1000
+ DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " unexpected code '(MyError)' in function " ) ,
1001
+ ] ,
1002
+ fixedSource: " func test() throws (MyError) {} " ,
1003
+ experimentalFeatures: [ . typedThrows]
1004
+ )
1005
+ assertParse (
1006
+ " func test() throws(MyError) {} " ,
1007
+ experimentalFeatures: [ . typedThrows]
1008
+ )
1009
+ assertParse (
1010
+ " func test() throws(MyError)1️⃣async {} " , // no space between closing parenthesis and `async`
1011
+ diagnostics: [
1012
+ DiagnosticSpec ( message: " 'async' must precede 'throws' " , fixIts: [ " move 'async' in front of 'throws' " ] )
1013
+ ] ,
1014
+ fixedSource: " func test() async throws(MyError){} " ,
1015
+ experimentalFeatures: [ . typedThrows]
1016
+ )
908
1017
}
909
1018
910
1019
func testExtraneousRightBraceRecovery( ) {
0 commit comments