diff options
| author | gingerBill <bill@gingerbill.org> | 2022-05-11 12:15:10 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-05-11 12:15:10 +0100 |
| commit | dca2fbccffd22b47cdb89e56170f3dae9a6257ad (patch) | |
| tree | 1f9007d4a4fa6a702f2bc85b215ee77496379dea | |
| parent | 8559790bd8e9e69187566ab3fa7855bbba2e7ec3 (diff) | |
Improve ternary if type inference
| -rw-r--r-- | src/check_expr.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 336a711d4..f578f8c73 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7241,7 +7241,11 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t node->viral_state_flags |= te->x->viral_state_flags; if (te->y != nullptr) { - check_expr_or_type(c, &y, te->y, type_hint); + Type *th = type_hint; + if (type_hint == nullptr && is_type_typed(x.type)) { + th = x.type; + } + check_expr_or_type(c, &y, te->y, th); node->viral_state_flags |= te->y->viral_state_flags; } else { error(node, "A ternary expression must have an else clause"); |