| ... | ... | @@ -1971,6 +1971,17 @@ fn comptimeExpr( |
| 1971 | 1971 | .block_two, .block_two_semicolon, .block, .block_semicolon => { |
| 1972 | 1972 | const token_tags = tree.tokens.items(.tag); |
| 1973 | 1973 | const lbrace = main_tokens[node]; |
| 1974 | // Careful! We can't pass in the real result location here, since it may |
| 1975 | // refer to runtime memory. A runtime-to-comptime boundary has to remove |
| 1976 | // result location information, compute the result, and copy it to the true |
| 1977 | // result location at runtime. We do this below as well. |
| 1978 | const ty_only_ri: ResultInfo = .{ |
| 1979 | .ctx = ri.ctx, |
| 1980 | .rl = if (try ri.rl.resultType(gz, node)) |res_ty| |
| 1981 | .{ .coerced_ty = res_ty } |
| 1982 | else |
| 1983 | .none, |
| 1984 | }; |
| 1974 | 1985 | if (token_tags[lbrace - 1] == .colon and |
| 1975 | 1986 | token_tags[lbrace - 2] == .identifier) |
| 1976 | 1987 | { |
| ... | ... | @@ -1985,17 +1996,13 @@ fn comptimeExpr( |
| 1985 | 1996 | else |
| 1986 | 1997 | stmts[0..2]; |
| 1987 | 1998 | |
| 1988 | | // Careful! We can't pass in the real result location here, since it may |
| 1989 | | // refer to runtime memory. A runtime-to-comptime boundary has to remove |
| 1990 | | // result location information, compute the result, and copy it to the true |
| 1991 | | // result location at runtime. We do this below as well. |
| 1992 | | const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmt_slice, true); |
| 1999 | const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmt_slice, true); |
| 1993 | 2000 | return rvalue(gz, ri, block_ref, node); |
| 1994 | 2001 | }, |
| 1995 | 2002 | .block, .block_semicolon => { |
| 1996 | 2003 | const stmts = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 1997 | 2004 | // Replace result location and copy back later - see above. |
| 1998 | | const block_ref = try labeledBlockExpr(gz, scope, .{ .rl = .none }, node, stmts, true); |
| 2005 | const block_ref = try labeledBlockExpr(gz, scope, ty_only_ri, node, stmts, true); |
| 1999 | 2006 | return rvalue(gz, ri, block_ref, node); |
| 2000 | 2007 | }, |
| 2001 | 2008 | else => unreachable, |
| ... | ... | @@ -2013,7 +2020,14 @@ fn comptimeExpr( |
| 2013 | 2020 | |
| 2014 | 2021 | const block_inst = try gz.makeBlockInst(.block_comptime, node); |
| 2015 | 2022 | // Replace result location and copy back later - see above. |
| 2016 | | const block_result = try expr(&block_scope, scope, .{ .rl = .none }, node); |
| 2023 | const ty_only_ri: ResultInfo = .{ |
| 2024 | .ctx = ri.ctx, |
| 2025 | .rl = if (try ri.rl.resultType(gz, node)) |res_ty| |
| 2026 | .{ .coerced_ty = res_ty } |
| 2027 | else |
| 2028 | .none, |
| 2029 | }; |
| 2030 | const block_result = try expr(&block_scope, scope, ty_only_ri, node); |
| 2017 | 2031 | if (!gz.refIsNoReturn(block_result)) { |
| 2018 | 2032 | _ = try block_scope.addBreak(.@"break", block_inst, block_result); |
| 2019 | 2033 | } |