| ... | @@ -2399,6 +2399,16 @@ static TypeTableEntry *resolve_expr_const_val_as_null(CodeGen *g, AstNode *node, | ... | @@ -2399,6 +2399,16 @@ static TypeTableEntry *resolve_expr_const_val_as_null(CodeGen *g, AstNode *node, |
| 2399 | return type; | 2399 | return type; |
| 2400 | } | 2400 | } |
| 2401 | | 2401 | |
| | 2402 | static TypeTableEntry *resolve_expr_const_val_as_non_null(CodeGen *g, AstNode *node, |
| | 2403 | TypeTableEntry *type, ConstExprValue *other_val) |
| | 2404 | { |
| | 2405 | assert(other_val->ok); |
| | 2406 | Expr *expr = get_resolved_expr(node); |
| | 2407 | expr->const_val.ok = true; |
| | 2408 | expr->const_val.data.x_maybe = other_val; |
| | 2409 | return type; |
| | 2410 | } |
| | 2411 | |
| 2402 | static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNode *node, Buf *str) { | 2412 | static TypeTableEntry *resolve_expr_const_val_as_c_string_lit(CodeGen *g, AstNode *node, Buf *str) { |
| 2403 | Expr *expr = get_resolved_expr(node); | 2413 | Expr *expr = get_resolved_expr(node); |
| 2404 | expr->const_val.ok = true; | 2414 | expr->const_val.ok = true; |
| ... | @@ -4376,8 +4386,12 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo | ... | @@ -4376,8 +4386,12 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo |
| 4376 | add_node_error(g, expr_node, buf_sprintf("unable to wrap unreachable in maybe type")); | 4386 | add_node_error(g, expr_node, buf_sprintf("unable to wrap unreachable in maybe type")); |
| 4377 | return g->builtin_types.entry_invalid; | 4387 | return g->builtin_types.entry_invalid; |
| 4378 | } else { | 4388 | } else { |
| 4379 | // TODO eval const expr | 4389 | ConstExprValue *target_const_val = &get_resolved_expr(expr_node)->const_val; |
| 4380 | return get_maybe_type(g, type_entry); | 4390 | TypeTableEntry *maybe_type = get_maybe_type(g, type_entry); |
| | 4391 | if (!target_const_val->ok) { |
| | 4392 | return maybe_type; |
| | 4393 | } |
| | 4394 | return resolve_expr_const_val_as_non_null(g, node, maybe_type, target_const_val); |
| 4381 | } | 4395 | } |
| 4382 | } | 4396 | } |
| 4383 | case PrefixOpError: | 4397 | case PrefixOpError: |