From ee21031fb16f5ed89dd1dbaf73bc2a1201f955b1 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 17 Aug 2019 16:30:28 -0400 Subject: Fix deal with and/or ops correctly in type checking --- sem_check.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sem_check.c b/sem_check.c index 7e6e338..d18fb59 100644 --- a/sem_check.c +++ b/sem_check.c @@ -56,6 +56,21 @@ ptree *t; if (!(t->r && t->l)) yyerror("Missing nodes\n"); + if (t->attr.opval == ADD || t->attr.opval == OR) { + if(t->l->ret_type == BOOL && t->r->ret_type ==BOOL) + return BOOL; + else { + type = t->l->ret_type == BOOL ? + t->r->ret_type : t->l->ret_type; + + snprintf(buf, 100, "Mismached types:" + "Cannot use boolean " + "operator on type %s\n", + pretty_type(type)); + yyerror(buf); + } + } + if (t->r->ret_type == t->l->ret_type) return t->r->ret_type; else { @@ -70,7 +85,6 @@ ptree *t; case RELOP : if (!(t->r && t->l)) yyerror("Missing nodes\n"); - if (t->r->ret_type == t->l->ret_type) return BOOL; else -- cgit v1.1