]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Some sanity checks for aliases (undeclared variable checks, and incompatible types...
authorDale Weiler <killfieldengine@gmail.com>
Wed, 6 Feb 2013 05:51:05 +0000 (05:51 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 6 Feb 2013 05:51:05 +0000 (05:51 +0000)
parser.c

index 80b9522a5a6a40ad4e01b16a6219d0149d4fe6da..7e86b23df1bafb92cf01f80cfa0817b80772d520 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5275,6 +5275,25 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                             }
                         }
                     } else {
+                        ast_expression *find = parser_find_var(parser, var->desc);
+                        if (!find) {
+                            compile_error(parser_ctx(parser), "undeclared variable `%s` for alias `%s", var->desc, var->name);
+                            return false;
+                        }
+
+                        if (var->expression.vtype != find->expression.vtype) {
+                            char ty1[1024];
+                            char ty2[1024];
+
+                            ast_type_to_string(find,                  ty1, sizeof(ty1));
+                            ast_type_to_string((ast_expression*)var,  ty2, sizeof(ty2));
+
+                            compile_error(parser_ctx(parser), "incompatible types `%s` and `%s` for alias `%s`",
+                                ty1, ty2, var->name
+                            );
+                            return false;
+                        }
+
                         util_htset(parser->aliases, var->name, (void*)var->desc);
                         /*
                          * TODO: vector, find . or _ (last of), and build