| author | |
| committer | |
| log | 644ea2dde9fbb1f948cf12115df2a15e908f3c29 |
| tree | 7d246fb67e4ffeadff496779a4ac4243fbbc46bc |
| parent | 0940d46c0160683fb5a28f66589e53ec5b64241d |
See #35719 files changed, 148 insertions(+), 226 deletions(-)
doc/langref.md+2-2| ... | @@ -91,9 +91,9 @@ Defer(body) = option("%") "defer" body | ... | @@ -91,9 +91,9 @@ Defer(body) = option("%") "defer" body |
| 91 | 91 | ||
| 92 | IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) | 92 | IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) |
| 93 | 93 | ||
| 94 | TryExpression(body) = "try" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" option("|" Symbol "|") BlockExpression(body)) | 94 | TryExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body "else" "|" Symbol "|" BlockExpression(body) |
| 95 | 95 | ||
| 96 | TestExpression(body) = "test" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" option("|" Symbol "|") BlockExpression(body)) | 96 | TestExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" BlockExpression(body)) |
| 97 | 97 | ||
| 98 | BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression | 98 | BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression |
| 99 | 99 |
src/ast_render.cpp+2-2| ... | @@ -763,7 +763,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -763,7 +763,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 763 | } | 763 | } |
| 764 | case NodeTypeTryExpr: | 764 | case NodeTypeTryExpr: |
| 765 | { | 765 | { |
| 766 | fprintf(ar->f, "try ("); | 766 | fprintf(ar->f, "if ("); |
| 767 | render_node_grouped(ar, node->data.try_expr.target_node); | 767 | render_node_grouped(ar, node->data.try_expr.target_node); |
| 768 | fprintf(ar->f, ") "); | 768 | fprintf(ar->f, ") "); |
| 769 | if (node->data.try_expr.var_symbol) { | 769 | if (node->data.try_expr.var_symbol) { |
| ... | @@ -783,7 +783,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { | ... | @@ -783,7 +783,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 783 | } | 783 | } |
| 784 | case NodeTypeTestExpr: | 784 | case NodeTypeTestExpr: |
| 785 | { | 785 | { |
| 786 | fprintf(ar->f, "test ("); | 786 | fprintf(ar->f, "if ("); |
| 787 | render_node_grouped(ar, node->data.test_expr.target_node); | 787 | render_node_grouped(ar, node->data.test_expr.target_node); |
| 788 | fprintf(ar->f, ") "); | 788 | fprintf(ar->f, ") "); |
| 789 | if (node->data.test_expr.var_symbol) { | 789 | if (node->data.test_expr.var_symbol) { |
src/parser.cpp+66-123| ... | @@ -215,7 +215,7 @@ static AstNode *ast_parse_block_or_expression(ParseContext *pc, size_t *token_in | ... | @@ -215,7 +215,7 @@ static AstNode *ast_parse_block_or_expression(ParseContext *pc, size_t *token_in |
| 215 | static AstNode *ast_parse_block_expr_or_expression(ParseContext *pc, size_t *token_index, bool mandatory); | 215 | static AstNode *ast_parse_block_expr_or_expression(ParseContext *pc, size_t *token_index, bool mandatory); |
| 216 | static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory); | 216 | static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool mandatory); |
| 217 | static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory); | 217 | static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory); |
| 218 | static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory); | 218 | static AstNode *ast_parse_if_try_test_expr(ParseContext *pc, size_t *token_index, bool mandatory); |
| 219 | static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory); | 219 | static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory); |
| 220 | static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory); | 220 | static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory); |
| 221 | static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory); | 221 | static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory); |
| ... | @@ -639,110 +639,6 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b | ... | @@ -639,110 +639,6 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b |
| 639 | return node; | 639 | return node; |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | /* | ||
| 643 | TryExpression(body) = "try" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" option("|" Symbol "|") BlockExpression(body)) | ||
| 644 | */ | ||
| 645 | static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | ||
| 646 | Token *try_token = &pc->tokens->at(*token_index); | ||
| 647 | if (try_token->id == TokenIdKeywordTry) { | ||
| 648 | *token_index += 1; | ||
| 649 | } else if (mandatory) { | ||
| 650 | ast_expect_token(pc, try_token, TokenIdKeywordTry); | ||
| 651 | zig_unreachable(); | ||
| 652 | } else { | ||
| 653 | return nullptr; | ||
| 654 | } | ||
| 655 | |||
| 656 | AstNode *node = ast_create_node(pc, NodeTypeTryExpr, try_token); | ||
| 657 | |||
| 658 | ast_eat_token(pc, token_index, TokenIdLParen); | ||
| 659 | node->data.try_expr.target_node = ast_parse_expression(pc, token_index, true); | ||
| 660 | ast_eat_token(pc, token_index, TokenIdRParen); | ||
| 661 | |||
| 662 | Token *open_bar_tok = &pc->tokens->at(*token_index); | ||
| 663 | if (open_bar_tok->id == TokenIdBinOr) { | ||
| 664 | *token_index += 1; | ||
| 665 | |||
| 666 | Token *star_tok = &pc->tokens->at(*token_index); | ||
| 667 | if (star_tok->id == TokenIdStar) { | ||
| 668 | *token_index += 1; | ||
| 669 | node->data.try_expr.var_is_ptr = true; | ||
| 670 | } | ||
| 671 | |||
| 672 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | ||
| 673 | node->data.try_expr.var_symbol = token_buf(var_name_tok); | ||
| 674 | |||
| 675 | ast_eat_token(pc, token_index, TokenIdBinOr); | ||
| 676 | } | ||
| 677 | |||
| 678 | node->data.try_expr.then_node = ast_parse_block_or_expression(pc, token_index, true); | ||
| 679 | |||
| 680 | Token *else_token = &pc->tokens->at(*token_index); | ||
| 681 | if (else_token->id == TokenIdKeywordElse) { | ||
| 682 | *token_index += 1; | ||
| 683 | Token *open_bar_tok = &pc->tokens->at(*token_index); | ||
| 684 | if (open_bar_tok->id == TokenIdBinOr) { | ||
| 685 | *token_index += 1; | ||
| 686 | |||
| 687 | Token *err_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | ||
| 688 | node->data.try_expr.err_symbol = token_buf(err_name_tok); | ||
| 689 | |||
| 690 | ast_eat_token(pc, token_index, TokenIdBinOr); | ||
| 691 | } | ||
| 692 | |||
| 693 | node->data.try_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); | ||
| 694 | } | ||
| 695 | |||
| 696 | return node; | ||
| 697 | } | ||
| 698 | |||
| 699 | /* | ||
| 700 | TestExpression(body) = "test" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" BlockExpression(body)) | ||
| 701 | */ | ||
| 702 | static AstNode *ast_parse_test_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | ||
| 703 | Token *test_token = &pc->tokens->at(*token_index); | ||
| 704 | if (test_token->id == TokenIdKeywordTest) { | ||
| 705 | *token_index += 1; | ||
| 706 | } else if (mandatory) { | ||
| 707 | ast_expect_token(pc, test_token, TokenIdKeywordTest); | ||
| 708 | zig_unreachable(); | ||
| 709 | } else { | ||
| 710 | return nullptr; | ||
| 711 | } | ||
| 712 | |||
| 713 | AstNode *node = ast_create_node(pc, NodeTypeTestExpr, test_token); | ||
| 714 | |||
| 715 | ast_eat_token(pc, token_index, TokenIdLParen); | ||
| 716 | node->data.test_expr.target_node = ast_parse_expression(pc, token_index, true); | ||
| 717 | ast_eat_token(pc, token_index, TokenIdRParen); | ||
| 718 | |||
| 719 | Token *open_bar_tok = &pc->tokens->at(*token_index); | ||
| 720 | if (open_bar_tok->id == TokenIdBinOr) { | ||
| 721 | *token_index += 1; | ||
| 722 | |||
| 723 | Token *star_tok = &pc->tokens->at(*token_index); | ||
| 724 | if (star_tok->id == TokenIdStar) { | ||
| 725 | *token_index += 1; | ||
| 726 | node->data.test_expr.var_is_ptr = true; | ||
| 727 | } | ||
| 728 | |||
| 729 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | ||
| 730 | node->data.test_expr.var_symbol = token_buf(var_name_tok); | ||
| 731 | |||
| 732 | ast_eat_token(pc, token_index, TokenIdBinOr); | ||
| 733 | } | ||
| 734 | |||
| 735 | node->data.test_expr.then_node = ast_parse_block_or_expression(pc, token_index, true); | ||
| 736 | |||
| 737 | Token *else_token = &pc->tokens->at(*token_index); | ||
| 738 | if (else_token->id == TokenIdKeywordElse) { | ||
| 739 | *token_index += 1; | ||
| 740 | node->data.test_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); | ||
| 741 | } | ||
| 742 | |||
| 743 | return node; | ||
| 744 | } | ||
| 745 | |||
| 746 | /* | 642 | /* |
| 747 | PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl | 643 | PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl |
| 748 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable" | 644 | KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable" |
| ... | @@ -1434,8 +1330,10 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, b | ... | @@ -1434,8 +1330,10 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, b |
| 1434 | 1330 | ||
| 1435 | /* | 1331 | /* |
| 1436 | IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) | 1332 | IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) |
| 1333 | TryExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body "else" "|" Symbol "|" BlockExpression(body) | ||
| 1334 | TestExpression(body) = "if" "(" Expression ")" "|" option("*") Symbol "|" body option("else" BlockExpression(body)) | ||
| 1437 | */ | 1335 | */ |
| 1438 | static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | 1336 | static AstNode *ast_parse_if_try_test_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 1439 | Token *if_token = &pc->tokens->at(*token_index); | 1337 | Token *if_token = &pc->tokens->at(*token_index); |
| 1440 | 1338 | ||
| 1441 | if (if_token->id == TokenIdKeywordIf) { | 1339 | if (if_token->id == TokenIdKeywordIf) { |
| ... | @@ -1448,19 +1346,72 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma | ... | @@ -1448,19 +1346,72 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, size_t *token_index, bool ma |
| 1448 | } | 1346 | } |
| 1449 | 1347 | ||
| 1450 | ast_eat_token(pc, token_index, TokenIdLParen); | 1348 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 1451 | 1349 | AstNode *condition = ast_parse_expression(pc, token_index, true); | |
| 1452 | AstNode *node = ast_create_node(pc, NodeTypeIfBoolExpr, if_token); | ||
| 1453 | node->data.if_bool_expr.condition = ast_parse_expression(pc, token_index, true); | ||
| 1454 | ast_eat_token(pc, token_index, TokenIdRParen); | 1350 | ast_eat_token(pc, token_index, TokenIdRParen); |
| 1455 | node->data.if_bool_expr.then_block = ast_parse_block_or_expression(pc, token_index, true); | ||
| 1456 | 1351 | ||
| 1457 | Token *else_token = &pc->tokens->at(*token_index); | 1352 | Token *open_bar_tok = &pc->tokens->at(*token_index); |
| 1458 | if (else_token->id == TokenIdKeywordElse) { | 1353 | Token *var_name_tok = nullptr; |
| 1354 | bool var_is_ptr = false; | ||
| 1355 | if (open_bar_tok->id == TokenIdBinOr) { | ||
| 1356 | *token_index += 1; | ||
| 1357 | |||
| 1358 | Token *star_tok = &pc->tokens->at(*token_index); | ||
| 1359 | if (star_tok->id == TokenIdStar) { | ||
| 1360 | *token_index += 1; | ||
| 1361 | var_is_ptr = true; | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | ||
| 1365 | |||
| 1366 | ast_eat_token(pc, token_index, TokenIdBinOr); | ||
| 1367 | } | ||
| 1368 | |||
| 1369 | AstNode *body_node = ast_parse_block_or_expression(pc, token_index, true); | ||
| 1370 | |||
| 1371 | Token *else_tok = &pc->tokens->at(*token_index); | ||
| 1372 | AstNode *else_node = nullptr; | ||
| 1373 | Token *err_name_tok = nullptr; | ||
| 1374 | if (else_tok->id == TokenIdKeywordElse) { | ||
| 1459 | *token_index += 1; | 1375 | *token_index += 1; |
| 1460 | node->data.if_bool_expr.else_node = ast_parse_block_expr_or_expression(pc, token_index, true); | 1376 | |
| 1377 | Token *else_bar_tok = &pc->tokens->at(*token_index); | ||
| 1378 | if (else_bar_tok->id == TokenIdBinOr) { | ||
| 1379 | *token_index += 1; | ||
| 1380 | |||
| 1381 | err_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | ||
| 1382 | |||
| 1383 | ast_eat_token(pc, token_index, TokenIdBinOr); | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | else_node = ast_parse_block_expr_or_expression(pc, token_index, true); | ||
| 1461 | } | 1387 | } |
| 1462 | 1388 | ||
| 1463 | return node; | 1389 | if (err_name_tok != nullptr) { |
| 1390 | AstNode *node = ast_create_node(pc, NodeTypeTryExpr, if_token); | ||
| 1391 | node->data.try_expr.target_node = condition; | ||
| 1392 | node->data.try_expr.var_is_ptr = var_is_ptr; | ||
| 1393 | if (var_name_tok != nullptr) { | ||
| 1394 | node->data.try_expr.var_symbol = token_buf(var_name_tok); | ||
| 1395 | } | ||
| 1396 | node->data.try_expr.then_node = body_node; | ||
| 1397 | node->data.try_expr.err_symbol = token_buf(err_name_tok); | ||
| 1398 | node->data.try_expr.else_node = else_node; | ||
| 1399 | return node; | ||
| 1400 | } else if (var_name_tok != nullptr) { | ||
| 1401 | AstNode *node = ast_create_node(pc, NodeTypeTestExpr, if_token); | ||
| 1402 | node->data.test_expr.target_node = condition; | ||
| 1403 | node->data.test_expr.var_is_ptr = var_is_ptr; | ||
| 1404 | node->data.test_expr.var_symbol = token_buf(var_name_tok); | ||
| 1405 | node->data.test_expr.then_node = body_node; | ||
| 1406 | node->data.test_expr.else_node = else_node; | ||
| 1407 | return node; | ||
| 1408 | } else { | ||
| 1409 | AstNode *node = ast_create_node(pc, NodeTypeIfBoolExpr, if_token); | ||
| 1410 | node->data.if_bool_expr.condition = condition; | ||
| 1411 | node->data.if_bool_expr.then_block = body_node; | ||
| 1412 | node->data.if_bool_expr.else_node = else_node; | ||
| 1413 | return node; | ||
| 1414 | } | ||
| 1464 | } | 1415 | } |
| 1465 | 1416 | ||
| 1466 | /* | 1417 | /* |
| ... | @@ -1848,7 +1799,7 @@ BlockExpression(body) = Block | IfExpression(body) | TryExpression(body) | TestE | ... | @@ -1848,7 +1799,7 @@ BlockExpression(body) = Block | IfExpression(body) | TryExpression(body) | TestE |
| 1848 | static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) { | 1799 | static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 1849 | Token *token = &pc->tokens->at(*token_index); | 1800 | Token *token = &pc->tokens->at(*token_index); |
| 1850 | 1801 | ||
| 1851 | AstNode *if_expr = ast_parse_if_expr(pc, token_index, false); | 1802 | AstNode *if_expr = ast_parse_if_try_test_expr(pc, token_index, false); |
| 1852 | if (if_expr) | 1803 | if (if_expr) |
| 1853 | return if_expr; | 1804 | return if_expr; |
| 1854 | 1805 | ||
| ... | @@ -1872,14 +1823,6 @@ static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool | ... | @@ -1872,14 +1823,6 @@ static AstNode *ast_parse_block_expr(ParseContext *pc, size_t *token_index, bool |
| 1872 | if (comptime_node) | 1823 | if (comptime_node) |
| 1873 | return comptime_node; | 1824 | return comptime_node; |
| 1874 | 1825 | ||
| 1875 | AstNode *try_node = ast_parse_try_expr(pc, token_index, false); | ||
| 1876 | if (try_node) | ||
| 1877 | return try_node; | ||
| 1878 | |||
| 1879 | AstNode *test_node = ast_parse_test_expr(pc, token_index, false); | ||
| 1880 | if (test_node) | ||
| 1881 | return test_node; | ||
| 1882 | |||
| 1883 | if (mandatory) | 1826 | if (mandatory) |
| 1884 | ast_invalid_token_error(pc, token); | 1827 | ast_invalid_token_error(pc, token); |
| 1885 | 1828 |
src/tokenizer.cpp-2| ... | @@ -138,7 +138,6 @@ static const struct ZigKeyword zig_keywords[] = { | ... | @@ -138,7 +138,6 @@ static const struct ZigKeyword zig_keywords[] = { |
| 138 | {"test", TokenIdKeywordTest}, | 138 | {"test", TokenIdKeywordTest}, |
| 139 | {"this", TokenIdKeywordThis}, | 139 | {"this", TokenIdKeywordThis}, |
| 140 | {"true", TokenIdKeywordTrue}, | 140 | {"true", TokenIdKeywordTrue}, |
| 141 | {"try", TokenIdKeywordTry}, | ||
| 142 | {"undefined", TokenIdKeywordUndefined}, | 141 | {"undefined", TokenIdKeywordUndefined}, |
| 143 | {"union", TokenIdKeywordUnion}, | 142 | {"union", TokenIdKeywordUnion}, |
| 144 | {"unreachable", TokenIdKeywordUnreachable}, | 143 | {"unreachable", TokenIdKeywordUnreachable}, |
| ... | @@ -1472,7 +1471,6 @@ const char * token_name(TokenId id) { | ... | @@ -1472,7 +1471,6 @@ const char * token_name(TokenId id) { |
| 1472 | case TokenIdKeywordTest: return "test"; | 1471 | case TokenIdKeywordTest: return "test"; |
| 1473 | case TokenIdKeywordThis: return "this"; | 1472 | case TokenIdKeywordThis: return "this"; |
| 1474 | case TokenIdKeywordTrue: return "true"; | 1473 | case TokenIdKeywordTrue: return "true"; |
| 1475 | case TokenIdKeywordTry: return "try"; | ||
| 1476 | case TokenIdKeywordUndefined: return "undefined"; | 1474 | case TokenIdKeywordUndefined: return "undefined"; |
| 1477 | case TokenIdKeywordUnion: return "union"; | 1475 | case TokenIdKeywordUnion: return "union"; |
| 1478 | case TokenIdKeywordUnreachable: return "unreachable"; | 1476 | case TokenIdKeywordUnreachable: return "unreachable"; |
src/tokenizer.hpp-1| ... | @@ -75,7 +75,6 @@ enum TokenId { | ... | @@ -75,7 +75,6 @@ enum TokenId { |
| 75 | TokenIdKeywordTest, | 75 | TokenIdKeywordTest, |
| 76 | TokenIdKeywordThis, | 76 | TokenIdKeywordThis, |
| 77 | TokenIdKeywordTrue, | 77 | TokenIdKeywordTrue, |
| 78 | TokenIdKeywordTry, | ||
| 79 | TokenIdKeywordUndefined, | 78 | TokenIdKeywordUndefined, |
| 80 | TokenIdKeywordUnion, | 79 | TokenIdKeywordUnion, |
| 81 | TokenIdKeywordUnreachable, | 80 | TokenIdKeywordUnreachable, |
std/buf_map.zig+1-1| ... | @@ -28,7 +28,7 @@ pub const BufMap = struct { | ... | @@ -28,7 +28,7 @@ pub const BufMap = struct { |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | pub fn set(self: &BufMap, key: []const u8, value: []const u8) -> %void { | 30 | pub fn set(self: &BufMap, key: []const u8, value: []const u8) -> %void { |
| 31 | test (self.hash_map.get(key)) |entry| { | 31 | if (self.hash_map.get(key)) |entry| { |
| 32 | const value_copy = %return self.copy(value); | 32 | const value_copy = %return self.copy(value); |
| 33 | %defer self.free(value_copy); | 33 | %defer self.free(value_copy); |
| 34 | _ = %return self.hash_map.put(key, value_copy); | 34 | _ = %return self.hash_map.put(key, value_copy); |
std/build.zig+13-13| ... | @@ -306,7 +306,7 @@ pub const Builder = struct { | ... | @@ -306,7 +306,7 @@ pub const Builder = struct { |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | fn processNixOSEnvVars(self: &Builder) { | 308 | fn processNixOSEnvVars(self: &Builder) { |
| 309 | test (os.getEnv("NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { | 309 | if (os.getEnv("NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { |
| 310 | var it = mem.split(nix_cflags_compile, ' '); | 310 | var it = mem.split(nix_cflags_compile, ' '); |
| 311 | while (true) { | 311 | while (true) { |
| 312 | const word = it.next() ?? break; | 312 | const word = it.next() ?? break; |
| ... | @@ -322,7 +322,7 @@ pub const Builder = struct { | ... | @@ -322,7 +322,7 @@ pub const Builder = struct { |
| 322 | } | 322 | } |
| 323 | } | 323 | } |
| 324 | } | 324 | } |
| 325 | test (os.getEnv("NIX_LDFLAGS")) |nix_ldflags| { | 325 | if (os.getEnv("NIX_LDFLAGS")) |nix_ldflags| { |
| 326 | var it = mem.split(nix_ldflags, ' '); | 326 | var it = mem.split(nix_ldflags, ' '); |
| 327 | while (true) { | 327 | while (true) { |
| 328 | const word = it.next() ?? break; | 328 | const word = it.next() ?? break; |
| ... | @@ -350,7 +350,7 @@ pub const Builder = struct { | ... | @@ -350,7 +350,7 @@ pub const Builder = struct { |
| 350 | .type_id = type_id, | 350 | .type_id = type_id, |
| 351 | .description = description, | 351 | .description = description, |
| 352 | }; | 352 | }; |
| 353 | test (%%self.available_options_map.put(name, available_option)) { | 353 | if (%%self.available_options_map.put(name, available_option) != null) { |
| 354 | debug.panic("Option '{}' declared twice", name); | 354 | debug.panic("Option '{}' declared twice", name); |
| 355 | } | 355 | } |
| 356 | %%self.available_options_list.append(available_option); | 356 | %%self.available_options_list.append(available_option); |
| ... | @@ -424,7 +424,7 @@ pub const Builder = struct { | ... | @@ -424,7 +424,7 @@ pub const Builder = struct { |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool { | 426 | pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool { |
| 427 | test (%%self.user_input_options.put(name, UserInputOption { | 427 | if (%%self.user_input_options.put(name, UserInputOption { |
| 428 | .name = name, | 428 | .name = name, |
| 429 | .value = UserValue.Scalar { value }, | 429 | .value = UserValue.Scalar { value }, |
| 430 | .used = false, | 430 | .used = false, |
| ... | @@ -461,7 +461,7 @@ pub const Builder = struct { | ... | @@ -461,7 +461,7 @@ pub const Builder = struct { |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool { | 463 | pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool { |
| 464 | test (%%self.user_input_options.put(name, UserInputOption { | 464 | if (%%self.user_input_options.put(name, UserInputOption { |
| 465 | .name = name, | 465 | .name = name, |
| 466 | .value = UserValue.Flag, | 466 | .value = UserValue.Flag, |
| 467 | .used = false, | 467 | .used = false, |
| ... | @@ -530,7 +530,7 @@ pub const Builder = struct { | ... | @@ -530,7 +530,7 @@ pub const Builder = struct { |
| 530 | exe_path: []const u8, args: []const []const u8) -> %void | 530 | exe_path: []const u8, args: []const []const u8) -> %void |
| 531 | { | 531 | { |
| 532 | if (self.verbose) { | 532 | if (self.verbose) { |
| 533 | test (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd); | 533 | if (cwd) |yes_cwd| %%io.stderr.print("cd {}; ", yes_cwd); |
| 534 | %%io.stderr.print("{}", exe_path); | 534 | %%io.stderr.print("{}", exe_path); |
| 535 | for (args) |arg| { | 535 | for (args) |arg| { |
| 536 | %%io.stderr.print(" {}", arg); | 536 | %%io.stderr.print(" {}", arg); |
| ... | @@ -821,7 +821,7 @@ pub const LibExeObjStep = struct { | ... | @@ -821,7 +821,7 @@ pub const LibExeObjStep = struct { |
| 821 | } | 821 | } |
| 822 | 822 | ||
| 823 | pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 { | 823 | pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 { |
| 824 | test (self.output_path) |output_path| { | 824 | if (self.output_path) |output_path| { |
| 825 | output_path | 825 | output_path |
| 826 | } else { | 826 | } else { |
| 827 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) | 827 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) |
| ... | @@ -833,7 +833,7 @@ pub const LibExeObjStep = struct { | ... | @@ -833,7 +833,7 @@ pub const LibExeObjStep = struct { |
| 833 | } | 833 | } |
| 834 | 834 | ||
| 835 | pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 { | 835 | pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 { |
| 836 | test (self.output_h_path) |output_h_path| { | 836 | if (self.output_h_path) |output_h_path| { |
| 837 | output_h_path | 837 | output_h_path |
| 838 | } else { | 838 | } else { |
| 839 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) | 839 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) |
| ... | @@ -885,7 +885,7 @@ pub const LibExeObjStep = struct { | ... | @@ -885,7 +885,7 @@ pub const LibExeObjStep = struct { |
| 885 | }; | 885 | }; |
| 886 | %%zig_args.append(cmd); | 886 | %%zig_args.append(cmd); |
| 887 | 887 | ||
| 888 | test (self.root_src) |root_src| { | 888 | if (self.root_src) |root_src| { |
| 889 | %%zig_args.append(builder.pathFromRoot(root_src)); | 889 | %%zig_args.append(builder.pathFromRoot(root_src)); |
| 890 | } | 890 | } |
| 891 | 891 | ||
| ... | @@ -950,7 +950,7 @@ pub const LibExeObjStep = struct { | ... | @@ -950,7 +950,7 @@ pub const LibExeObjStep = struct { |
| 950 | }, | 950 | }, |
| 951 | } | 951 | } |
| 952 | 952 | ||
| 953 | test (self.linker_script) |linker_script| { | 953 | if (self.linker_script) |linker_script| { |
| 954 | %%zig_args.append("--linker-script"); | 954 | %%zig_args.append("--linker-script"); |
| 955 | %%zig_args.append(linker_script); | 955 | %%zig_args.append(linker_script); |
| 956 | } | 956 | } |
| ... | @@ -1059,7 +1059,7 @@ pub const TestStep = struct { | ... | @@ -1059,7 +1059,7 @@ pub const TestStep = struct { |
| 1059 | builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"), | 1059 | builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"), |
| 1060 | } | 1060 | } |
| 1061 | 1061 | ||
| 1062 | test (self.filter) |filter| { | 1062 | if (self.filter) |filter| { |
| 1063 | %%zig_args.append("--test-filter"); | 1063 | %%zig_args.append("--test-filter"); |
| 1064 | %%zig_args.append(filter); | 1064 | %%zig_args.append(filter); |
| 1065 | } | 1065 | } |
| ... | @@ -1203,7 +1203,7 @@ pub const CLibExeObjStep = struct { | ... | @@ -1203,7 +1203,7 @@ pub const CLibExeObjStep = struct { |
| 1203 | } | 1203 | } |
| 1204 | 1204 | ||
| 1205 | pub fn getOutputPath(self: &CLibExeObjStep) -> []const u8 { | 1205 | pub fn getOutputPath(self: &CLibExeObjStep) -> []const u8 { |
| 1206 | test (self.output_path) |output_path| { | 1206 | if (self.output_path) |output_path| { |
| 1207 | output_path | 1207 | output_path |
| 1208 | } else { | 1208 | } else { |
| 1209 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) | 1209 | %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) |
| ... | @@ -1492,7 +1492,7 @@ pub const CommandStep = struct { | ... | @@ -1492,7 +1492,7 @@ pub const CommandStep = struct { |
| 1492 | fn make(step: &Step) -> %void { | 1492 | fn make(step: &Step) -> %void { |
| 1493 | const self = @fieldParentPtr(CommandStep, "step", step); | 1493 | const self = @fieldParentPtr(CommandStep, "step", step); |
| 1494 | 1494 | ||
| 1495 | const cwd = test (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else null; | 1495 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else null; |
| 1496 | return self.builder.spawnChildEnvMap(cwd, self.env_map, self.exe_path, self.args); | 1496 | return self.builder.spawnChildEnvMap(cwd, self.env_map, self.exe_path, self.args); |
| 1497 | } | 1497 | } |
| 1498 | }; | 1498 | }; |
std/debug.zig+8-8| ... | @@ -98,13 +98,13 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty | ... | @@ -98,13 +98,13 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 98 | continue; | 98 | continue; |
| 99 | }; | 99 | }; |
| 100 | const compile_unit_name = %return compile_unit.die.getAttrString(st, DW.AT_name); | 100 | const compile_unit_name = %return compile_unit.die.getAttrString(st, DW.AT_name); |
| 101 | try (getLineNumberInfo(st, compile_unit, usize(return_address) - 1)) |line_info| { | 101 | if (getLineNumberInfo(st, compile_unit, usize(return_address) - 1)) |line_info| { |
| 102 | defer line_info.deinit(); | 102 | defer line_info.deinit(); |
| 103 | %return out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ | 103 | %return out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ |
| 104 | DIM ++ ptr_hex ++ " in ??? ({})" ++ RESET ++ "\n", | 104 | DIM ++ ptr_hex ++ " in ??? ({})" ++ RESET ++ "\n", |
| 105 | line_info.file_name, line_info.line, line_info.column, | 105 | line_info.file_name, line_info.line, line_info.column, |
| 106 | return_address, compile_unit_name); | 106 | return_address, compile_unit_name); |
| 107 | try (printLineFromFile(st.allocator(), out_stream, line_info)) { | 107 | if (printLineFromFile(st.allocator(), out_stream, line_info)) { |
| 108 | if (line_info.column == 0) { | 108 | if (line_info.column == 0) { |
| 109 | %return out_stream.write("\n"); | 109 | %return out_stream.write("\n"); |
| 110 | } else { | 110 | } else { |
| ... | @@ -679,7 +679,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -679,7 +679,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 679 | DW.LNE_end_sequence => { | 679 | DW.LNE_end_sequence => { |
| 680 | //%%io.stdout.printf(" [0x{x8}] End Sequence\n", pos); | 680 | //%%io.stdout.printf(" [0x{x8}] End Sequence\n", pos); |
| 681 | prog.end_sequence = true; | 681 | prog.end_sequence = true; |
| 682 | test (%return prog.checkLineMatch()) |info| return info; | 682 | if (%return prog.checkLineMatch()) |info| return info; |
| 683 | return error.MissingDebugInfo; | 683 | return error.MissingDebugInfo; |
| 684 | }, | 684 | }, |
| 685 | DW.LNE_set_address => { | 685 | DW.LNE_set_address => { |
| ... | @@ -717,14 +717,14 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe | ... | @@ -717,14 +717,14 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 717 | //%%io.stdout.printf( | 717 | //%%io.stdout.printf( |
| 718 | // " [0x{x8}] Special opcode {}: advance Address by {} to 0x{x} and Line by {} to {}\n", | 718 | // " [0x{x8}] Special opcode {}: advance Address by {} to 0x{x} and Line by {} to {}\n", |
| 719 | // pos, adjusted_opcode, inc_addr, prog.address, inc_line, prog.line); | 719 | // pos, adjusted_opcode, inc_addr, prog.address, inc_line, prog.line); |
| 720 | test (%return prog.checkLineMatch()) |info| return info; | 720 | if (%return prog.checkLineMatch()) |info| return info; |
| 721 | prog.basic_block = false; | 721 | prog.basic_block = false; |
| 722 | } else { | 722 | } else { |
| 723 | switch (opcode) { | 723 | switch (opcode) { |
| 724 | DW.LNS_copy => { | 724 | DW.LNS_copy => { |
| 725 | //%%io.stdout.printf(" [0x{x8}] Copy\n", pos); | 725 | //%%io.stdout.printf(" [0x{x8}] Copy\n", pos); |
| 726 | 726 | ||
| 727 | test (%return prog.checkLineMatch()) |info| return info; | 727 | if (%return prog.checkLineMatch()) |info| return info; |
| 728 | prog.basic_block = false; | 728 | prog.basic_block = false; |
| 729 | }, | 729 | }, |
| 730 | DW.LNS_advance_pc => { | 730 | DW.LNS_advance_pc => { |
| ... | @@ -828,8 +828,8 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { | ... | @@ -828,8 +828,8 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { |
| 828 | return error.InvalidDebugInfo; | 828 | return error.InvalidDebugInfo; |
| 829 | 829 | ||
| 830 | const pc_range = { | 830 | const pc_range = { |
| 831 | try (compile_unit_die.getAttrAddr(DW.AT_low_pc)) |low_pc| { | 831 | if (compile_unit_die.getAttrAddr(DW.AT_low_pc)) |low_pc| { |
| 832 | test (compile_unit_die.getAttr(DW.AT_high_pc)) |high_pc_value| { | 832 | if (compile_unit_die.getAttr(DW.AT_high_pc)) |high_pc_value| { |
| 833 | const pc_end = switch (*high_pc_value) { | 833 | const pc_end = switch (*high_pc_value) { |
| 834 | FormValue.Address => |value| value, | 834 | FormValue.Address => |value| value, |
| 835 | FormValue.Const => |value| { | 835 | FormValue.Const => |value| { |
| ... | @@ -867,7 +867,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { | ... | @@ -867,7 +867,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void { |
| 867 | 867 | ||
| 868 | fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> ?&const CompileUnit { | 868 | fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> ?&const CompileUnit { |
| 869 | for (st.compile_unit_list.toSlice()) |*compile_unit| { | 869 | for (st.compile_unit_list.toSlice()) |*compile_unit| { |
| 870 | test (compile_unit.pc_range) |range| { | 870 | if (compile_unit.pc_range) |range| { |
| 871 | if (target_address >= range.start and target_address < range.end) | 871 | if (target_address >= range.start and target_address < range.end) |
| 872 | return compile_unit; | 872 | return compile_unit; |
| 873 | } | 873 | } |
std/hash_map.zig+1-1| ... | @@ -247,7 +247,7 @@ test "basicHashMapTest" { | ... | @@ -247,7 +247,7 @@ test "basicHashMapTest" { |
| 247 | assert((??map.get(2)).value == 22); | 247 | assert((??map.get(2)).value == 22); |
| 248 | _ = map.remove(2); | 248 | _ = map.remove(2); |
| 249 | assert(map.remove(2) == null); | 249 | assert(map.remove(2) == null); |
| 250 | assert(test (map.get(2)) false else true); | 250 | assert(map.get(2) == null); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | fn hash_i32(x: i32) -> u32 { | 253 | fn hash_i32(x: i32) -> u32 { |
std/linked_list.zig+6-6| ... | @@ -43,7 +43,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -43,7 +43,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 43 | /// new_node: Pointer to the new node to insert. | 43 | /// new_node: Pointer to the new node to insert. |
| 44 | pub fn insertAfter(list: &List, node: &Node, new_node: &Node) { | 44 | pub fn insertAfter(list: &List, node: &Node, new_node: &Node) { |
| 45 | new_node.prev = node; | 45 | new_node.prev = node; |
| 46 | test (node.next) |next_node| { | 46 | if (node.next) |next_node| { |
| 47 | // Intermediate node. | 47 | // Intermediate node. |
| 48 | new_node.next = next_node; | 48 | new_node.next = next_node; |
| 49 | next_node.prev = new_node; | 49 | next_node.prev = new_node; |
| ... | @@ -64,7 +64,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -64,7 +64,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 64 | /// new_node: Pointer to the new node to insert. | 64 | /// new_node: Pointer to the new node to insert. |
| 65 | pub fn insertBefore(list: &List, node: &Node, new_node: &Node) { | 65 | pub fn insertBefore(list: &List, node: &Node, new_node: &Node) { |
| 66 | new_node.next = node; | 66 | new_node.next = node; |
| 67 | test (node.prev) |prev_node| { | 67 | if (node.prev) |prev_node| { |
| 68 | // Intermediate node. | 68 | // Intermediate node. |
| 69 | new_node.prev = prev_node; | 69 | new_node.prev = prev_node; |
| 70 | prev_node.next = new_node; | 70 | prev_node.next = new_node; |
| ... | @@ -83,7 +83,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -83,7 +83,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 83 | /// Arguments: | 83 | /// Arguments: |
| 84 | /// new_node: Pointer to the new node to insert. | 84 | /// new_node: Pointer to the new node to insert. |
| 85 | pub fn append(list: &List, new_node: &Node) { | 85 | pub fn append(list: &List, new_node: &Node) { |
| 86 | test (list.last) |last| { | 86 | if (list.last) |last| { |
| 87 | // Insert after last. | 87 | // Insert after last. |
| 88 | list.insertAfter(last, new_node); | 88 | list.insertAfter(last, new_node); |
| 89 | } else { | 89 | } else { |
| ... | @@ -97,7 +97,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -97,7 +97,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 97 | /// Arguments: | 97 | /// Arguments: |
| 98 | /// new_node: Pointer to the new node to insert. | 98 | /// new_node: Pointer to the new node to insert. |
| 99 | pub fn prepend(list: &List, new_node: &Node) { | 99 | pub fn prepend(list: &List, new_node: &Node) { |
| 100 | test (list.first) |first| { | 100 | if (list.first) |first| { |
| 101 | // Insert before first. | 101 | // Insert before first. |
| 102 | list.insertBefore(first, new_node); | 102 | list.insertBefore(first, new_node); |
| 103 | } else { | 103 | } else { |
| ... | @@ -116,7 +116,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -116,7 +116,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 116 | /// Arguments: | 116 | /// Arguments: |
| 117 | /// node: Pointer to the node to be removed. | 117 | /// node: Pointer to the node to be removed. |
| 118 | pub fn remove(list: &List, node: &Node) { | 118 | pub fn remove(list: &List, node: &Node) { |
| 119 | test (node.prev) |prev_node| { | 119 | if (node.prev) |prev_node| { |
| 120 | // Intermediate node. | 120 | // Intermediate node. |
| 121 | prev_node.next = node.next; | 121 | prev_node.next = node.next; |
| 122 | } else { | 122 | } else { |
| ... | @@ -124,7 +124,7 @@ pub fn LinkedList(comptime T: type) -> type { | ... | @@ -124,7 +124,7 @@ pub fn LinkedList(comptime T: type) -> type { |
| 124 | list.first = node.next; | 124 | list.first = node.next; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | test (node.next) |next_node| { | 127 | if (node.next) |next_node| { |
| 128 | // Intermediate node. | 128 | // Intermediate node. |
| 129 | next_node.prev = node.prev; | 129 | next_node.prev = node.prev; |
| 130 | } else { | 130 | } else { |
std/os/child_process.zig+7-7| ... | @@ -59,9 +59,9 @@ pub const ChildProcess = struct { | ... | @@ -59,9 +59,9 @@ pub const ChildProcess = struct { |
| 59 | errno.EINVAL, errno.ECHILD => unreachable, | 59 | errno.EINVAL, errno.ECHILD => unreachable, |
| 60 | errno.EINTR => continue, | 60 | errno.EINTR => continue, |
| 61 | else => { | 61 | else => { |
| 62 | test (self.stdin) |*stdin| { stdin.close(); } | 62 | if (self.stdin) |*stdin| { stdin.close(); } |
| 63 | test (self.stdout) |*stdout| { stdout.close(); } | 63 | if (self.stdout) |*stdout| { stdout.close(); } |
| 64 | test (self.stderr) |*stderr| { stderr.close(); } | 64 | if (self.stderr) |*stderr| { stderr.close(); } |
| 65 | return error.Unexpected; | 65 | return error.Unexpected; |
| 66 | }, | 66 | }, |
| 67 | } | 67 | } |
| ... | @@ -69,9 +69,9 @@ pub const ChildProcess = struct { | ... | @@ -69,9 +69,9 @@ pub const ChildProcess = struct { |
| 69 | break; | 69 | break; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | test (self.stdin) |*stdin| { stdin.close(); } | 72 | if (self.stdin) |*stdin| { stdin.close(); } |
| 73 | test (self.stdout) |*stdout| { stdout.close(); } | 73 | if (self.stdout) |*stdout| { stdout.close(); } |
| 74 | test (self.stderr) |*stderr| { stderr.close(); } | 74 | if (self.stderr) |*stderr| { stderr.close(); } |
| 75 | 75 | ||
| 76 | // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after | 76 | // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after |
| 77 | // waitpid, so this write is guaranteed to be after the child | 77 | // waitpid, so this write is guaranteed to be after the child |
| ... | @@ -143,7 +143,7 @@ pub const ChildProcess = struct { | ... | @@ -143,7 +143,7 @@ pub const ChildProcess = struct { |
| 143 | setUpChildIo(stderr, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) %% | 143 | setUpChildIo(stderr, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) %% |
| 144 | |err| forkChildErrReport(err_pipe[1], err); | 144 | |err| forkChildErrReport(err_pipe[1], err); |
| 145 | 145 | ||
| 146 | test (maybe_cwd) |cwd| { | 146 | if (maybe_cwd) |cwd| { |
| 147 | os.changeCurDir(allocator, cwd) %% | 147 | os.changeCurDir(allocator, cwd) %% |
| 148 | |err| forkChildErrReport(err_pipe[1], err); | 148 | |err| forkChildErrReport(err_pipe[1], err); |
| 149 | } | 149 | } |
std/os/index.zig+6-6| ... | @@ -173,7 +173,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?& | ... | @@ -173,7 +173,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?& |
| 173 | 173 | ||
| 174 | if (file_path.len < stack_buf.len) { | 174 | if (file_path.len < stack_buf.len) { |
| 175 | path0 = stack_buf[0...file_path.len + 1]; | 175 | path0 = stack_buf[0...file_path.len + 1]; |
| 176 | } else test (allocator) |a| { | 176 | } else if (allocator) |a| { |
| 177 | path0 = %return a.alloc(u8, file_path.len + 1); | 177 | path0 = %return a.alloc(u8, file_path.len + 1); |
| 178 | need_free = true; | 178 | need_free = true; |
| 179 | } else { | 179 | } else { |
| ... | @@ -241,7 +241,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con | ... | @@ -241,7 +241,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con |
| 241 | mem.set(?&u8, argv_buf, null); | 241 | mem.set(?&u8, argv_buf, null); |
| 242 | defer { | 242 | defer { |
| 243 | for (argv_buf) |arg| { | 243 | for (argv_buf) |arg| { |
| 244 | const arg_buf = test (arg) |ptr| cstr.toSlice(ptr) else break; | 244 | const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break; |
| 245 | allocator.free(arg_buf); | 245 | allocator.free(arg_buf); |
| 246 | } | 246 | } |
| 247 | allocator.free(argv_buf); | 247 | allocator.free(argv_buf); |
| ... | @@ -268,7 +268,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con | ... | @@ -268,7 +268,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con |
| 268 | mem.set(?&u8, envp_buf, null); | 268 | mem.set(?&u8, envp_buf, null); |
| 269 | defer { | 269 | defer { |
| 270 | for (envp_buf) |env| { | 270 | for (envp_buf) |env| { |
| 271 | const env_buf = test (env) |ptr| cstr.toSlice(ptr) else break; | 271 | const env_buf = if (env) |ptr| cstr.toSlice(ptr) else break; |
| 272 | allocator.free(env_buf); | 272 | allocator.free(env_buf); |
| 273 | } | 273 | } |
| 274 | allocator.free(envp_buf); | 274 | allocator.free(envp_buf); |
| ... | @@ -448,7 +448,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con | ... | @@ -448,7 +448,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con |
| 448 | const b64_fs_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; | 448 | const b64_fs_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; |
| 449 | 449 | ||
| 450 | pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { | 450 | pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void { |
| 451 | try (symLink(allocator, existing_path, new_path)) { | 451 | if (symLink(allocator, existing_path, new_path)) { |
| 452 | return; | 452 | return; |
| 453 | } else |err| { | 453 | } else |err| { |
| 454 | if (err != error.PathAlreadyExists) { | 454 | if (err != error.PathAlreadyExists) { |
| ... | @@ -463,7 +463,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: | ... | @@ -463,7 +463,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: |
| 463 | while (true) { | 463 | while (true) { |
| 464 | %return getRandomBytes(rand_buf[0...]); | 464 | %return getRandomBytes(rand_buf[0...]); |
| 465 | _ = base64.encodeWithAlphabet(tmp_path[new_path.len...], rand_buf, b64_fs_alphabet); | 465 | _ = base64.encodeWithAlphabet(tmp_path[new_path.len...], rand_buf, b64_fs_alphabet); |
| 466 | try (symLink(allocator, existing_path, tmp_path)) { | 466 | if (symLink(allocator, existing_path, tmp_path)) { |
| 467 | return rename(allocator, tmp_path, new_path); | 467 | return rename(allocator, tmp_path, new_path); |
| 468 | } else |err| { | 468 | } else |err| { |
| 469 | if (err == error.PathAlreadyExists) { | 469 | if (err == error.PathAlreadyExists) { |
| ... | @@ -668,7 +668,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { | ... | @@ -668,7 +668,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) -> %void { |
| 668 | pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { | 668 | pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void { |
| 669 | start_over: | 669 | start_over: |
| 670 | // First, try deleting the item as a file. This way we don't follow sym links. | 670 | // First, try deleting the item as a file. This way we don't follow sym links. |
| 671 | try (deleteFile(allocator, full_path)) { | 671 | if (deleteFile(allocator, full_path)) { |
| 672 | return; | 672 | return; |
| 673 | } else |err| { | 673 | } else |err| { |
| 674 | if (err == error.FileNotFound) | 674 | if (err == error.FileNotFound) |
std/os/path.zig+1-1| ... | @@ -243,7 +243,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u | ... | @@ -243,7 +243,7 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u |
| 243 | while (true) { | 243 | while (true) { |
| 244 | const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); | 244 | const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); |
| 245 | const to_rest = to_it.rest(); | 245 | const to_rest = to_it.rest(); |
| 246 | test(to_it.next()) |to_component| { | 246 | if (to_it.next()) |to_component| { |
| 247 | if (mem.eql(u8, from_component, to_component)) | 247 | if (mem.eql(u8, from_component, to_component)) |
| 248 | continue; | 248 | continue; |
| 249 | } | 249 | } |
std/special/build_runner.zig+1-1| ... | @@ -63,7 +63,7 @@ pub fn main() -> %void { | ... | @@ -63,7 +63,7 @@ pub fn main() -> %void { |
| 63 | %%io.stderr.printf("Expected option name after '-D'\n\n"); | 63 | %%io.stderr.printf("Expected option name after '-D'\n\n"); |
| 64 | return usage(&builder, false, &io.stderr); | 64 | return usage(&builder, false, &io.stderr); |
| 65 | } | 65 | } |
| 66 | test (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { | 66 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| 67 | const option_name = option_contents[0...name_end]; | 67 | const option_name = option_contents[0...name_end]; |
| 68 | const option_value = option_contents[name_end + 1...]; | 68 | const option_value = option_contents[name_end + 1...]; |
| 69 | if (builder.addUserInputOption(option_name, option_value)) | 69 | if (builder.addUserInputOption(option_name, option_value)) |
std/special/compiler_rt.zig+9-9| ... | @@ -36,7 +36,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -36,7 +36,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 36 | // 0 X | 36 | // 0 X |
| 37 | // --- | 37 | // --- |
| 38 | // 0 X | 38 | // 0 X |
| 39 | test (maybe_rem) |rem| { | 39 | if (maybe_rem) |rem| { |
| 40 | *rem = n[low] % d[low]; | 40 | *rem = n[low] % d[low]; |
| 41 | } | 41 | } |
| 42 | return n[low] / d[low]; | 42 | return n[low] / d[low]; |
| ... | @@ -44,7 +44,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -44,7 +44,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 44 | // 0 X | 44 | // 0 X |
| 45 | // --- | 45 | // --- |
| 46 | // K X | 46 | // K X |
| 47 | test (maybe_rem) |rem| { | 47 | if (maybe_rem) |rem| { |
| 48 | *rem = n[low]; | 48 | *rem = n[low]; |
| 49 | } | 49 | } |
| 50 | return 0; | 50 | return 0; |
| ... | @@ -55,7 +55,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -55,7 +55,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 55 | // K X | 55 | // K X |
| 56 | // --- | 56 | // --- |
| 57 | // 0 0 | 57 | // 0 0 |
| 58 | test (maybe_rem) |rem| { | 58 | if (maybe_rem) |rem| { |
| 59 | *rem = n[high] % d[low]; | 59 | *rem = n[high] % d[low]; |
| 60 | } | 60 | } |
| 61 | return n[high] / d[low]; | 61 | return n[high] / d[low]; |
| ... | @@ -65,7 +65,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -65,7 +65,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 65 | // K 0 | 65 | // K 0 |
| 66 | // --- | 66 | // --- |
| 67 | // K 0 | 67 | // K 0 |
| 68 | test (maybe_rem) |rem| { | 68 | if (maybe_rem) |rem| { |
| 69 | r[high] = n[high] % d[high]; | 69 | r[high] = n[high] % d[high]; |
| 70 | r[low] = 0; | 70 | r[low] = 0; |
| 71 | *rem = *@ptrCast(&du_int, &r[0]); | 71 | *rem = *@ptrCast(&du_int, &r[0]); |
| ... | @@ -77,7 +77,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -77,7 +77,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 77 | // K 0 | 77 | // K 0 |
| 78 | // if d is a power of 2 | 78 | // if d is a power of 2 |
| 79 | if ((d[high] & (d[high] - 1)) == 0) { | 79 | if ((d[high] & (d[high] - 1)) == 0) { |
| 80 | test (maybe_rem) |rem| { | 80 | if (maybe_rem) |rem| { |
| 81 | r[low] = n[low]; | 81 | r[low] = n[low]; |
| 82 | r[high] = n[high] & (d[high] - 1); | 82 | r[high] = n[high] & (d[high] - 1); |
| 83 | *rem = *@ptrCast(&du_int, &r[0]); | 83 | *rem = *@ptrCast(&du_int, &r[0]); |
| ... | @@ -90,7 +90,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -90,7 +90,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 90 | sr = @clz(su_int(d[high])) - @clz(su_int(n[high])); | 90 | sr = @clz(su_int(d[high])) - @clz(su_int(n[high])); |
| 91 | // 0 <= sr <= n_uword_bits - 2 or sr large | 91 | // 0 <= sr <= n_uword_bits - 2 or sr large |
| 92 | if (sr > n_uword_bits - 2) { | 92 | if (sr > n_uword_bits - 2) { |
| 93 | test (maybe_rem) |rem| { | 93 | if (maybe_rem) |rem| { |
| 94 | *rem = *@ptrCast(&du_int, &n[0]); | 94 | *rem = *@ptrCast(&du_int, &n[0]); |
| 95 | } | 95 | } |
| 96 | return 0; | 96 | return 0; |
| ... | @@ -111,7 +111,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -111,7 +111,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 111 | // 0 K | 111 | // 0 K |
| 112 | // if d is a power of 2 | 112 | // if d is a power of 2 |
| 113 | if ((d[low] & (d[low] - 1)) == 0) { | 113 | if ((d[low] & (d[low] - 1)) == 0) { |
| 114 | test (maybe_rem) |rem| { | 114 | if (maybe_rem) |rem| { |
| 115 | *rem = n[low] & (d[low] - 1); | 115 | *rem = n[low] & (d[low] - 1); |
| 116 | } | 116 | } |
| 117 | if (d[low] == 1) { | 117 | if (d[low] == 1) { |
| ... | @@ -155,7 +155,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -155,7 +155,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 155 | sr = @clz(su_int(d[high])) - @clz(su_int(n[high])); | 155 | sr = @clz(su_int(d[high])) - @clz(su_int(n[high])); |
| 156 | // 0 <= sr <= n_uword_bits - 1 or sr large | 156 | // 0 <= sr <= n_uword_bits - 1 or sr large |
| 157 | if (sr > n_uword_bits - 1) { | 157 | if (sr > n_uword_bits - 1) { |
| 158 | test (maybe_rem) |rem| { | 158 | if (maybe_rem) |rem| { |
| 159 | *rem = *@ptrCast(&du_int, &n[0]); | 159 | *rem = *@ptrCast(&du_int, &n[0]); |
| 160 | } | 160 | } |
| 161 | return 0; | 161 | return 0; |
| ... | @@ -200,7 +200,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { | ... | @@ -200,7 +200,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { |
| 200 | sr -= 1; | 200 | sr -= 1; |
| 201 | } | 201 | } |
| 202 | *@ptrCast(&du_int, &q[0]) = (*@ptrCast(&du_int, &q[0]) << 1) | u64(carry); | 202 | *@ptrCast(&du_int, &q[0]) = (*@ptrCast(&du_int, &q[0]) << 1) | u64(carry); |
| 203 | test (maybe_rem) |rem| { | 203 | if (maybe_rem) |rem| { |
| 204 | *rem = *@ptrCast(&du_int, &r[0]); | 204 | *rem = *@ptrCast(&du_int, &r[0]); |
| 205 | } | 205 | } |
| 206 | return *@ptrCast(&du_int, &q[0]); | 206 | return *@ptrCast(&du_int, &q[0]); |
test/cases/null.zig+6-6| ... | @@ -3,7 +3,7 @@ const assert = @import("std").debug.assert; | ... | @@ -3,7 +3,7 @@ const assert = @import("std").debug.assert; |
| 3 | test "nullableType" { | 3 | test "nullableType" { |
| 4 | const x : ?bool = @generatedCode(true); | 4 | const x : ?bool = @generatedCode(true); |
| 5 | 5 | ||
| 6 | test (x) |y| { | 6 | if (x) |y| { |
| 7 | if (y) { | 7 | if (y) { |
| 8 | // OK | 8 | // OK |
| 9 | } else { | 9 | } else { |
| ... | @@ -29,7 +29,7 @@ test "nullableType" { | ... | @@ -29,7 +29,7 @@ test "nullableType" { |
| 29 | test "test maybe object and get a pointer to the inner value" { | 29 | test "test maybe object and get a pointer to the inner value" { |
| 30 | var maybe_bool: ?bool = true; | 30 | var maybe_bool: ?bool = true; |
| 31 | 31 | ||
| 32 | test (maybe_bool) |*b| { | 32 | if (maybe_bool) |*b| { |
| 33 | *b = false; | 33 | *b = false; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -50,7 +50,7 @@ test "maybe return" { | ... | @@ -50,7 +50,7 @@ test "maybe return" { |
| 50 | 50 | ||
| 51 | fn maybeReturnImpl() { | 51 | fn maybeReturnImpl() { |
| 52 | assert(??foo(1235)); | 52 | assert(??foo(1235)); |
| 53 | test (foo(null)) | 53 | if (foo(null) != null) |
| 54 | unreachable; | 54 | unreachable; |
| 55 | assert(!??foo(1234)); | 55 | assert(!??foo(1234)); |
| 56 | } | 56 | } |
| ... | @@ -66,10 +66,10 @@ test "ifVarMaybePointer" { | ... | @@ -66,10 +66,10 @@ test "ifVarMaybePointer" { |
| 66 | } | 66 | } |
| 67 | fn shouldBeAPlus1(p: &const Particle) -> u64 { | 67 | fn shouldBeAPlus1(p: &const Particle) -> u64 { |
| 68 | var maybe_particle: ?Particle = *p; | 68 | var maybe_particle: ?Particle = *p; |
| 69 | test (maybe_particle) |*particle| { | 69 | if (maybe_particle) |*particle| { |
| 70 | particle.a += 1; | 70 | particle.a += 1; |
| 71 | } | 71 | } |
| 72 | test (maybe_particle) |particle| { | 72 | if (maybe_particle) |particle| { |
| 73 | return particle.a; | 73 | return particle.a; |
| 74 | } | 74 | } |
| 75 | return 0; | 75 | return 0; |
| ... | @@ -116,7 +116,7 @@ fn nullableVoidImpl() { | ... | @@ -116,7 +116,7 @@ fn nullableVoidImpl() { |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | fn bar(x: ?void) -> ?void { | 118 | fn bar(x: ?void) -> ?void { |
| 119 | test (x) { | 119 | if (x) |_| { |
| 120 | return {}; | 120 | return {}; |
| 121 | } else { | 121 | } else { |
| 122 | return null; | 122 | return null; |
test/cases/try.zig+6-6| ... | @@ -7,7 +7,7 @@ test "tryOnErrorUnion" { | ... | @@ -7,7 +7,7 @@ test "tryOnErrorUnion" { |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | fn tryOnErrorUnionImpl() { | 9 | fn tryOnErrorUnionImpl() { |
| 10 | const x = try (returnsTen()) |val| { | 10 | const x = if (returnsTen()) |val| { |
| 11 | val + 1 | 11 | val + 1 |
| 12 | } else |err| switch (err) { | 12 | } else |err| switch (err) { |
| 13 | error.ItBroke, error.NoMem => 1, | 13 | error.ItBroke, error.NoMem => 1, |
| ... | @@ -24,16 +24,16 @@ fn returnsTen() -> %i32 { | ... | @@ -24,16 +24,16 @@ fn returnsTen() -> %i32 { |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | test "tryWithoutVars" { | 26 | test "tryWithoutVars" { |
| 27 | const result1 = try (failIfTrue(true)) { | 27 | const result1 = if (failIfTrue(true)) { |
| 28 | 1 | 28 | 1 |
| 29 | } else { | 29 | } else |_| { |
| 30 | i32(2) | 30 | i32(2) |
| 31 | }; | 31 | }; |
| 32 | assert(result1 == 2); | 32 | assert(result1 == 2); |
| 33 | 33 | ||
| 34 | const result2 = try (failIfTrue(false)) { | 34 | const result2 = if (failIfTrue(false)) { |
| 35 | 1 | 35 | 1 |
| 36 | } else { | 36 | } else |_| { |
| 37 | i32(2) | 37 | i32(2) |
| 38 | }; | 38 | }; |
| 39 | assert(result2 == 1); | 39 | assert(result2 == 1); |
| ... | @@ -48,7 +48,7 @@ fn failIfTrue(ok: bool) -> %void { | ... | @@ -48,7 +48,7 @@ fn failIfTrue(ok: bool) -> %void { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | test "try then not executed with assignment" { | 50 | test "try then not executed with assignment" { |
| 51 | try (failIfTrue(true)) { | 51 | if (failIfTrue(true)) { |
| 52 | unreachable; | 52 | unreachable; |
| 53 | } else |err| { | 53 | } else |err| { |
| 54 | assert(err == error.ItBroke); | 54 | assert(err == error.ItBroke); |
test/compile_errors.zig+6-24| ... | @@ -118,38 +118,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -118,38 +118,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 118 | \\} | 118 | \\} |
| 119 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); | 119 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 120 | 120 | ||
| 121 | cases.add("implicit semicolon - try statement", | ||
| 122 | \\export fn entry() { | ||
| 123 | \\ try (foo()) {} | ||
| 124 | \\ var good = {}; | ||
| 125 | \\ try (foo()) ({}) | ||
| 126 | \\ var bad = {}; | ||
| 127 | \\} | ||
| 128 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); | ||
| 129 | |||
| 130 | cases.add("implicit semicolon - try expression", | ||
| 131 | \\export fn entry() { | ||
| 132 | \\ _ = try (foo()) {}; | ||
| 133 | \\ var good = {}; | ||
| 134 | \\ _ = try (foo()) {} | ||
| 135 | \\ var bad = {}; | ||
| 136 | \\} | ||
| 137 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); | ||
| 138 | |||
| 139 | cases.add("implicit semicolon - test statement", | 121 | cases.add("implicit semicolon - test statement", |
| 140 | \\export fn entry() { | 122 | \\export fn entry() { |
| 141 | \\ test (foo()) {} | 123 | \\ if (foo()) |_| {} |
| 142 | \\ var good = {}; | 124 | \\ var good = {}; |
| 143 | \\ test (foo()) ({}) | 125 | \\ if (foo()) |_| ({}) |
| 144 | \\ var bad = {}; | 126 | \\ var bad = {}; |
| 145 | \\} | 127 | \\} |
| 146 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); | 128 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 147 | 129 | ||
| 148 | cases.add("implicit semicolon - test expression", | 130 | cases.add("implicit semicolon - test expression", |
| 149 | \\export fn entry() { | 131 | \\export fn entry() { |
| 150 | \\ _ = test (foo()) {}; | 132 | \\ _ = if (foo()) |_| {}; |
| 151 | \\ var good = {}; | 133 | \\ var good = {}; |
| 152 | \\ _ = test (foo()) {} | 134 | \\ _ = if (foo()) |_| {} |
| 153 | \\ var bad = {}; | 135 | \\ var bad = {}; |
| 154 | \\} | 136 | \\} |
| 155 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); | 137 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| ... | @@ -500,9 +482,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -500,9 +482,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 500 | 482 | ||
| 501 | cases.add("invalid maybe type", | 483 | cases.add("invalid maybe type", |
| 502 | \\export fn f() { | 484 | \\export fn f() { |
| 503 | \\ test (true) |x| { } | 485 | \\ if (true) |x| { } |
| 504 | \\} | 486 | \\} |
| 505 | , ".tmp_source.zig:2:11: error: expected nullable type, found 'bool'"); | 487 | , ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'"); |
| 506 | 488 | ||
| 507 | cases.add("cast unreachable", | 489 | cases.add("cast unreachable", |
| 508 | \\fn f() -> i32 { | 490 | \\fn f() -> i32 { |
test/tests.zig+7-7| ... | @@ -349,7 +349,7 @@ pub const CompareOutputContext = struct { | ... | @@ -349,7 +349,7 @@ pub const CompareOutputContext = struct { |
| 349 | switch (case.special) { | 349 | switch (case.special) { |
| 350 | Special.Asm => { | 350 | Special.Asm => { |
| 351 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name); | 351 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name); |
| 352 | test (self.test_filter) |filter| { | 352 | if (self.test_filter) |filter| { |
| 353 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 353 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 354 | return; | 354 | return; |
| 355 | } | 355 | } |
| ... | @@ -373,7 +373,7 @@ pub const CompareOutputContext = struct { | ... | @@ -373,7 +373,7 @@ pub const CompareOutputContext = struct { |
| 373 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { | 373 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { |
| 374 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})", | 374 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})", |
| 375 | "compare-output", case.name, @enumTagName(mode)); | 375 | "compare-output", case.name, @enumTagName(mode)); |
| 376 | test (self.test_filter) |filter| { | 376 | if (self.test_filter) |filter| { |
| 377 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 377 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 378 | continue; | 378 | continue; |
| 379 | } | 379 | } |
| ... | @@ -399,7 +399,7 @@ pub const CompareOutputContext = struct { | ... | @@ -399,7 +399,7 @@ pub const CompareOutputContext = struct { |
| 399 | }, | 399 | }, |
| 400 | Special.DebugSafety => { | 400 | Special.DebugSafety => { |
| 401 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name); | 401 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name); |
| 402 | test (self.test_filter) |filter| { | 402 | if (self.test_filter) |filter| { |
| 403 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 403 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 404 | return; | 404 | return; |
| 405 | } | 405 | } |
| ... | @@ -620,7 +620,7 @@ pub const CompileErrorContext = struct { | ... | @@ -620,7 +620,7 @@ pub const CompileErrorContext = struct { |
| 620 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { | 620 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { |
| 621 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})", | 621 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})", |
| 622 | case.name, @enumTagName(mode)); | 622 | case.name, @enumTagName(mode)); |
| 623 | test (self.test_filter) |filter| { | 623 | if (self.test_filter) |filter| { |
| 624 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 624 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 625 | continue; | 625 | continue; |
| 626 | } | 626 | } |
| ... | @@ -655,7 +655,7 @@ pub const BuildExamplesContext = struct { | ... | @@ -655,7 +655,7 @@ pub const BuildExamplesContext = struct { |
| 655 | const b = self.b; | 655 | const b = self.b; |
| 656 | 656 | ||
| 657 | const annotated_case_name = b.fmt("build {} (Debug)", build_file); | 657 | const annotated_case_name = b.fmt("build {} (Debug)", build_file); |
| 658 | test (self.test_filter) |filter| { | 658 | if (self.test_filter) |filter| { |
| 659 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 659 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 660 | return; | 660 | return; |
| 661 | } | 661 | } |
| ... | @@ -686,7 +686,7 @@ pub const BuildExamplesContext = struct { | ... | @@ -686,7 +686,7 @@ pub const BuildExamplesContext = struct { |
| 686 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { | 686 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { |
| 687 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})", | 687 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})", |
| 688 | root_src, @enumTagName(mode)); | 688 | root_src, @enumTagName(mode)); |
| 689 | test (self.test_filter) |filter| { | 689 | if (self.test_filter) |filter| { |
| 690 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 690 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 691 | continue; | 691 | continue; |
| 692 | } | 692 | } |
| ... | @@ -874,7 +874,7 @@ pub const ParseHContext = struct { | ... | @@ -874,7 +874,7 @@ pub const ParseHContext = struct { |
| 874 | const b = self.b; | 874 | const b = self.b; |
| 875 | 875 | ||
| 876 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parseh {}", case.name); | 876 | const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parseh {}", case.name); |
| 877 | test (self.test_filter) |filter| { | 877 | if (self.test_filter) |filter| { |
| 878 | if (mem.indexOf(u8, annotated_case_name, filter) == null) | 878 | if (mem.indexOf(u8, annotated_case_name, filter) == null) |
| 879 | return; | 879 | return; |
| 880 | } | 880 | } |