aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorJasperGeer <jasper.geer@gmail.com>2022-09-04 15:31:05 -0400
committerJasperGeer <jasper.geer@gmail.com>2022-09-04 15:31:05 -0400
commit2e3dd8dd0b0af28d031f78791b738da514602f7b (patch)
tree8c31f000aa10261c4100d3ac9481b642297bff9f /src/check_expr.cpp
parent8421cb6d21e6b0a397dd9a31e76b97aba5c1852b (diff)
Err on types passed as operands to ternary if expressions
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 54dc081cf..c3528c859 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -7347,6 +7347,13 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t
check_expr_or_type(c, &x, te->x, type_hint);
node->viral_state_flags |= te->x->viral_state_flags;
+ if (x.mode == Addressing_Type || x.mode == Addressing_Type) {
+ gbString type_string = expr_to_string(x.expr);
+ error(node, "Type %s is invalid operand for ternary if expression", type_string);
+ gb_string_free(type_string);
+ return kind;
+ }
+
if (te->y != nullptr) {
Type *th = type_hint;
if (type_hint == nullptr && is_type_typed(x.type)) {
@@ -7359,6 +7366,13 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t
return kind;
}
+ if (y.mode == Addressing_Type || y.mode == Addressing_Type) {
+ gbString type_string = expr_to_string(y.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) {
return kind;