From 49ed4310fdba52fe946a7eac062a8b972d6087c2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 10 Jun 2019 08:46:40 +0900 Subject: [PATCH] Fix assigning int to enum or enum to int Or float, for v6 progs. --- tools/qfcc/source/expr_assign.c | 7 ++++++- tools/qfcc/test/enum.r | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/expr_assign.c b/tools/qfcc/source/expr_assign.c index 1662d6b10..b32f6de9e 100644 --- a/tools/qfcc/source/expr_assign.c +++ b/tools/qfcc/source/expr_assign.c @@ -149,7 +149,12 @@ check_types_compatible (expr_t *dst, expr_t *src) if (type_assignable (dst_type, src_type)) { if (is_scalar (dst_type) && is_scalar (src_type)) { // the types are different but cast-compatible - return assign_expr (dst, cast_expr (dst_type, src)); + expr_t *new = cast_expr (dst_type, src); + // the cast was a no-op, so the types are compatible at the + // low level (very true for default type <-> enum) + if (new != src) { + return assign_expr (dst, new); + } } return 0; } diff --git a/tools/qfcc/test/enum.r b/tools/qfcc/test/enum.r index b6ffb09c1..f1565cdf0 100644 --- a/tools/qfcc/test/enum.r +++ b/tools/qfcc/test/enum.r @@ -7,6 +7,7 @@ int main() { BOOL b; + b = 0; b = YES; return !b; }