File tree Expand file tree Collapse file tree 2 files changed +70
-2
lines changed Expand file tree Collapse file tree 2 files changed +70
-2
lines changed Original file line number Diff line number Diff line change @@ -1914,11 +1914,12 @@ def _parse_fn_end(self, fn: Function) -> None:
1914
1914
fn_template = fn_template [0 ]
1915
1915
fn_template .raw_requires_post = self ._parse_requires (rtok )
1916
1916
1917
+ if self .lex .token_if ("ARROW" ):
1918
+ self ._parse_trailing_return_type (fn )
1919
+
1917
1920
if self .lex .token_if ("{" ):
1918
1921
self ._discard_contents ("{" , "}" )
1919
1922
fn .has_body = True
1920
- elif self .lex .token_if ("ARROW" ):
1921
- self ._parse_trailing_return_type (fn )
1922
1923
1923
1924
def _parse_method_end (self , method : Method ) -> None :
1924
1925
"""
@@ -1963,6 +1964,9 @@ def _parse_method_end(self, method: Method) -> None:
1963
1964
method .ref_qualifier = tok_value
1964
1965
elif tok_value == "->" :
1965
1966
self ._parse_trailing_return_type (method )
1967
+ if self .lex .token_if ("{" ):
1968
+ self ._discard_contents ("{" , "}" )
1969
+ method .has_body = True
1966
1970
break
1967
1971
elif tok_value == "throw" :
1968
1972
tok = self ._next_token_must_be ("(" )
Original file line number Diff line number Diff line change @@ -1194,3 +1194,67 @@ class C {
1194
1194
]
1195
1195
)
1196
1196
)
1197
+
1198
+
1199
+ def test_fn_trailing_return_with_body () -> None :
1200
+ content = """
1201
+ auto test() -> void
1202
+ {
1203
+ }
1204
+ """
1205
+ data = parse_string (content , cleandoc = True )
1206
+
1207
+ assert data == ParsedData (
1208
+ namespace = NamespaceScope (
1209
+ functions = [
1210
+ Function (
1211
+ return_type = Type (
1212
+ typename = PQName (segments = [FundamentalSpecifier (name = "void" )])
1213
+ ),
1214
+ name = PQName (segments = [NameSpecifier (name = "test" )]),
1215
+ parameters = [],
1216
+ has_body = True ,
1217
+ has_trailing_return = True ,
1218
+ )
1219
+ ]
1220
+ )
1221
+ )
1222
+
1223
+
1224
+ def test_method_trailing_return_with_body () -> None :
1225
+ content = """
1226
+ struct X {
1227
+ auto test() -> void
1228
+ {
1229
+ }
1230
+ };
1231
+ """
1232
+ data = parse_string (content , cleandoc = True )
1233
+
1234
+ assert data == ParsedData (
1235
+ namespace = NamespaceScope (
1236
+ classes = [
1237
+ ClassScope (
1238
+ class_decl = ClassDecl (
1239
+ typename = PQName (
1240
+ segments = [NameSpecifier (name = "X" )], classkey = "struct"
1241
+ )
1242
+ ),
1243
+ methods = [
1244
+ Method (
1245
+ return_type = Type (
1246
+ typename = PQName (
1247
+ segments = [FundamentalSpecifier (name = "void" )]
1248
+ )
1249
+ ),
1250
+ name = PQName (segments = [NameSpecifier (name = "test" )]),
1251
+ parameters = [],
1252
+ has_body = True ,
1253
+ has_trailing_return = True ,
1254
+ access = "public" ,
1255
+ )
1256
+ ],
1257
+ )
1258
+ ]
1259
+ )
1260
+ )
You can’t perform that action at this time.
0 commit comments