diff --git a/src/prolang.y b/src/prolang.y index 4f0408bd4..2a242971c 100644 --- a/src/prolang.y +++ b/src/prolang.y @@ -6680,7 +6680,7 @@ find_struct ( ident_t * ident, efun_override_t override ) lt->t_struct.def_idx = LAMBDA_STRUCTS_COUNT; assign_svalue_no_free(&ref_str, str); /* Add a reference. */ - idx = store_lambda_value(str); + idx = store_lambda_value(&ref_str); name->u.global.struct_id = LAMBDA_STRUCTS_COUNT; ADD_LAMBDA_STRUCT((lambda_struct_ident_t){ @@ -8659,7 +8659,7 @@ lookup_function (ident_t *ident, char* super, efun_override_t override) int idx; assign_svalue_no_free(&ref_fun, fun); /* Add a reference. */ - idx = store_lambda_value(fun); + idx = store_lambda_value(&ref_fun); ident->u.global.function = LAMBDA_FUNCTIONS_COUNT; ADD_LAMBDA_FUNCTION((lambda_ident_t){.kind = LAMBDA_IDENT_VALUE, .value_index = idx}); @@ -8770,7 +8770,7 @@ lookup_global_variable (ident_t *ident) int idx; assign_svalue_no_free(&ref_var, var); /* Add a reference. */ - idx = store_lambda_value(var); + idx = store_lambda_value(&ref_var); ident->u.global.variable = LAMBDA_VARIABLES_COUNT; ADD_LAMBDA_VARIABLE((lambda_ident_t){.kind = LAMBDA_IDENT_VALUE, .value_index = idx}); diff --git a/test/t-efuns.c b/test/t-efuns.c index 4f51ea1d3..6e282b13c 100644 --- a/test/t-efuns.c +++ b/test/t-efuns.c @@ -463,6 +463,15 @@ mixed *tests = }))) == "ABCZ"; :) }), + ({ "compile_string (same function multiple times from function)", 0, + (: + return funcall(compile_string(0, "fun1() + fun2() + fun3()", ( + functions: function closure(symbol name) : closure cl = function int() { return 10; } + { + return cl; + }))) == 30; + :) + }), ({ "compile_string (missing function from function)", TF_ERROR, (: compile_string(0, "fun1() + fun2(\"z\")", ( @@ -541,6 +550,15 @@ mixed *tests = }))) == "ABCX" && v2 == "X"; :) }), + ({ "compile_string (same value multiple times from function)", 0, + (: + return funcall(compile_string(0, "a+b+c", ( + variables: function mixed(symbol name) : int value = 10 + { + return &value; + }))) == 30; + :) + }), ({ "compile_string (variable, missing in function)", TF_ERROR, (: string v1 = "ABC"; @@ -628,6 +646,16 @@ mixed *tests = })); :) }), + ({ "compile_string (same struct multiple times from function)", 0, + (: + return deep_eq(funcall(compile_string(0, + "({ ( ({10})), ( ({20})), ( ({30})) })", ( + structs: function struct mixed(symbol name) : struct test_struct s = () + { + return s; + }))), ({ ( ({10})), ( ({20})), ( ({30})) })); + :) + }), ({ "compile_string (struct from object)", 0, (: return deep_eq(funcall(compile_string(0, "( ({10}))", ( use_object_structs: 1))),