harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit cc69317b8e60c86eff3d3833b19c1a033f56caf5
parent 20743b3ab5e588b45436215460441476b47d03ac
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sat, 23 Apr 2022 10:35:50 +0000

check: limit switch exprs to comparable types

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Msrc/check.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -2423,6 +2423,16 @@ check_expr_switch(struct context *ctx, check_expression(ctx, aexpr->_switch.value, value, NULL); const struct type *type = type_dealias(value->result); expr->_switch.value = value; + if (!type_is_numeric(type) + && type_dealias(type)->storage != STORAGE_POINTER + && type_dealias(type)->storage != STORAGE_STRING + && type_dealias(type)->storage != STORAGE_BOOL + && type_dealias(type)->storage != STORAGE_RCONST + && type_dealias(type)->storage != STORAGE_RUNE) { + error(ctx, aexpr->loc, expr, + "Cannot switch on %s type", + type_storage_unparse(type_dealias(type)->storage)); + } struct type_tagged_union result_type = {0}; struct type_tagged_union *tagged = &result_type,