diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-05 16:06:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-05 16:06:40 +0100 |
| commit | 37e23133e9877c6d30604be8d586363b3cf412ed (patch) | |
| tree | fc09ed8a360ce3a29e2809b355b8f5db1fa87b33 /src/check_expr.cpp | |
| parent | 91fd9c1ef297e9cc08c1daee5d4f09cfdef70b57 (diff) | |
Fix #2018 type assertion on untyped nil within a ternary if expression
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 0b6e108a3..959bbb078 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7359,13 +7359,13 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t return kind; } - if (x.mode == Addressing_Type || y.mode == Addressing_Type) { - Ast *type_expr = (x.mode == Addressing_Type) ? x.expr : y.expr; - gbString type_string = expr_to_string(type_expr); - error(node, "Type %s is invalid operand for ternary if expression", type_string); - gb_string_free(type_string); - return kind; - } + if (x.mode == Addressing_Type || y.mode == Addressing_Type) { + Ast *type_expr = (x.mode == Addressing_Type) ? x.expr : y.expr; + gbString type_string = expr_to_string(type_expr); + error(node, "Type %s is invalid operand for ternary if expression", type_string); + gb_string_free(type_string); + return kind; + } if (x.type == nullptr || x.type == t_invalid || y.type == nullptr || y.type == t_invalid) { @@ -7403,6 +7403,7 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t check_cast_internal(c, &y, type_hint)) { convert_to_typed(c, o, type_hint); update_untyped_expr_type(c, node, type_hint, !is_type_untyped(type_hint)); + o->type = type_hint; } } return kind; |