data/vars.qc - when declaring a function, and it had a prototype - use the new parameter names instead of the ones from the prototype, otherwise things get messy

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-18 20:16:51 +02:00
parent 99fe673f0a
commit 588cd5018f
2 changed files with 25 additions and 0 deletions

19
data/vars.qc Normal file
View file

@ -0,0 +1,19 @@
/* this is the WIP test for the parser...
* constantly adding stuff here to see if things break
*/
void(string) print = #1;
void(string,string) print2 = #1;
void(string,string,string) print3 = #1;
string(float) ftos = #2;
entity() spawn = #3;
void(entity) kill = #4;
float(vector different_name, vector b) dot;
float(vector a, vector b) dot = {
return a * b;
};
void() main = {
print3("should be 1: ", ftos(dot('1 1 0', '1 0 0')), "\n");
};

View file

@ -1838,6 +1838,7 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
* messing with the parameter-vector etc. earlier * messing with the parameter-vector etc. earlier
*/ */
if (proto) { if (proto) {
size_t param;
if (!ast_compare_type((ast_expression*)proto, (ast_expression*)fval)) { if (!ast_compare_type((ast_expression*)proto, (ast_expression*)fval)) {
parseerror(parser, "conflicting types for `%s`, previous declaration was here: %s:%i", parseerror(parser, "conflicting types for `%s`, previous declaration was here: %s:%i",
proto->name, proto->name,
@ -1846,6 +1847,11 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
ast_value_delete(fval); ast_value_delete(fval);
return false; return false;
} }
/* copy over the parameter names */
for (param = 0; param < fval->expression.params_count; ++param)
ast_value_set_name(proto->expression.params[param], fval->expression.params[param]->name);
/* now ditch the rest of the new data */
ast_function_delete(func); ast_function_delete(func);
ast_value_delete(fval); ast_value_delete(fval);
fval = proto; fval = proto;