From e28ee0378fa20013c6fe4b1e31bb604264891df7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 18 Nov 2010 09:02:12 +0900 Subject: [PATCH] Gracefully handle returning NIL though a bad type. --- tools/qfcc/source/expr.c | 2 ++ tools/qfcc/test/nil.r | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 7f9f18fa4..28b66c41d 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2138,6 +2138,8 @@ return_expr (function_t *f, expr_t *e) if (e->type == ex_nil) { t = f->def->type->aux_type; e->type = expr_types[t->type]; + if (e->type == ex_nil) + return error (e, "invalid return type for NIL"); } else { if (!options.traditional) return error (e, "void value not ignored as it ought to be"); diff --git a/tools/qfcc/test/nil.r b/tools/qfcc/test/nil.r index 2b6a193ce..b261a25bf 100644 --- a/tools/qfcc/test/nil.r +++ b/tools/qfcc/test/nil.r @@ -1 +1,18 @@ Class x = NIL; + +struct Size { + integer x; + integer y; +}; +typedef struct Size Size; + +@interface foo +-(Size) bar; +@end +@implementation foo +-(Size) bar +{ + local Size s; + return NIL; +} +@end