@@ -763,18 +763,22 @@ pub fn block(input: ParseInput) -> ParseResult<ParseInput, Ast> {
763763 let input = next ( input) ;
764764 let ( input, start_loc) = position ( input) ?;
765765
766- if let Ok ( ( input, _) ) = tokens:: if_tok ( input) {
767- unit_if ( input, start_loc. into ( ) )
766+ let ( input , stmt ) = if let Ok ( ( input, _) ) = tokens:: if_tok ( input) {
767+ unit_if ( input, start_loc. into ( ) ) ?
768768 } else if let Ok ( ( input, kind) ) =
769769 alt ( ( tokens:: func_tok, tokens:: test_tok, tokens:: mock_tok) ) ( input)
770770 {
771- unit_func ( input, kind, start_loc. into ( ) )
771+ unit_func ( input, kind, start_loc. into ( ) ) ?
772772 } else if tokens:: left_curly_bracket ( input) . is_ok ( ) {
773773 // we don't update `input` here so that we can just call `block`
774- block ( input)
774+ block ( input) ?
775775 } else {
776- expr_semicolon ( input)
777- }
776+ expr_semicolon ( input) ?
777+ } ;
778+
779+ let ( input, _) = opt ( tokens:: semicolon) ( input) ?;
780+
781+ Ok ( ( input, stmt) )
778782 } ;
779783
780784 let ( input, stmts) = opt ( many1 ( stmt) ) ( input) ?;
@@ -2329,4 +2333,37 @@ mod tests {
23292333
23302334 assert ! ( expr( input) . is_ok( ) ) ;
23312335 }
2336+
2337+ #[ test]
2338+ fn early_return395 ( ) {
2339+ let input = span ! ( "func halloween(b: bool) -> int { if b { return 14 }; 15 }" ) ;
2340+
2341+ assert ! ( expr( input) . is_ok( ) ) ;
2342+ }
2343+
2344+ #[ test]
2345+ fn inner_block_with_semi395 ( ) {
2346+ let input = span ! (
2347+ "func halloween() -> int { func inner() -> int { { { { { return 14; } } } } }; 15 }"
2348+ ) ;
2349+
2350+ assert ! ( expr( input) . is_ok( ) )
2351+ }
2352+
2353+ #[ test]
2354+ fn inner_nested_function395 ( ) {
2355+ let input = span ! { r#"
2356+ func halloween() -> string {
2357+ func inner() -> string {
2358+ { { { {
2359+ return "boo";
2360+ } } } }
2361+ };
2362+
2363+ "different string"
2364+ }
2365+ "# } ;
2366+
2367+ assert ! ( expr( input) . is_ok( ) )
2368+ }
23322369}
0 commit comments