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