| ... | ... | @@ -841,13 +841,16 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 841 | 841 | .@"if", |
| 842 | 842 | => { |
| 843 | 843 | const if_full = tree.fullIf(node).?; |
| 844 | | if (if_full.error_token) |error_token| { |
| 845 | | const tag = node_tags[if_full.ast.else_expr]; |
| 846 | | if ((tag == .@"switch" or tag == .switch_comma) and |
| 847 | | std.mem.eql(u8, tree.tokenSlice(error_token), tree.tokenSlice(error_token + 4))) |
| 848 | | { |
| 849 | | return switchExprErrUnion(gz, scope, ri.br(), node, .@"if"); |
| 844 | no_switch_on_err: { |
| 845 | const error_token = if_full.error_token orelse break :no_switch_on_err; |
| 846 | switch (node_tags[if_full.ast.else_expr]) { |
| 847 | .@"switch", .switch_comma => {}, |
| 848 | else => break :no_switch_on_err, |
| 850 | 849 | } |
| 850 | const switch_operand = node_datas[if_full.ast.else_expr].lhs; |
| 851 | if (node_tags[switch_operand] != .identifier) break :no_switch_on_err; |
| 852 | if (!mem.eql(u8, tree.tokenSlice(error_token), tree.tokenSlice(main_tokens[switch_operand]))) break :no_switch_on_err; |
| 853 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"if"); |
| 851 | 854 | } |
| 852 | 855 | return ifExpr(gz, scope, ri.br(), node, if_full); |
| 853 | 856 | }, |
| ... | ... | @@ -1026,16 +1029,21 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 1026 | 1029 | }, |
| 1027 | 1030 | .@"catch" => { |
| 1028 | 1031 | const catch_token = main_tokens[node]; |
| 1029 | | const payload_token: ?Ast.TokenIndex = if (token_tags[catch_token + 1] == .pipe) blk: { |
| 1030 | | if (token_tags.len > catch_token + 6 and |
| 1031 | | token_tags[catch_token + 4] == .keyword_switch) |
| 1032 | | { |
| 1033 | | if (std.mem.eql(u8, tree.tokenSlice(catch_token + 2), tree.tokenSlice(catch_token + 6))) { |
| 1034 | | return switchExprErrUnion(gz, scope, ri.br(), node, .@"catch"); |
| 1035 | | } |
| 1032 | const payload_token: ?Ast.TokenIndex = if (token_tags[catch_token + 1] == .pipe) |
| 1033 | catch_token + 2 |
| 1034 | else |
| 1035 | null; |
| 1036 | no_switch_on_err: { |
| 1037 | const capture_token = payload_token orelse break :no_switch_on_err; |
| 1038 | switch (node_tags[node_datas[node].rhs]) { |
| 1039 | .@"switch", .switch_comma => {}, |
| 1040 | else => break :no_switch_on_err, |
| 1036 | 1041 | } |
| 1037 | | break :blk catch_token + 2; |
| 1038 | | } else null; |
| 1042 | const switch_operand = node_datas[node_datas[node].rhs].lhs; |
| 1043 | if (node_tags[switch_operand] != .identifier) break :no_switch_on_err; |
| 1044 | if (!mem.eql(u8, tree.tokenSlice(capture_token), tree.tokenSlice(main_tokens[switch_operand]))) break :no_switch_on_err; |
| 1045 | return switchExprErrUnion(gz, scope, ri.br(), node, .@"catch"); |
| 1046 | } |
| 1039 | 1047 | switch (ri.rl) { |
| 1040 | 1048 | .ref, .ref_coerced_ty => return orelseCatchExpr( |
| 1041 | 1049 | gz, |