diff --git a/src/special.c b/src/special.c index ce35aab..1e80a5e 100644 --- a/src/special.c +++ b/src/special.c @@ -152,14 +152,14 @@ struct ucl_object *ucl_special_while(struct ucl_scope *scope, struct ucl_object struct ucl_object *ucl_special_setq(struct ucl_scope *scope, struct ucl_object *args) { // TODO: Check arguments struct ucl_object *sym = ucl_car(args); - struct ucl_scope *root_scope = ucl_scope_get_root(scope); if (sym->type != UCL_TYPE_SYMBOL) { return ucl_error_create("First argument to setq must be a symbol"); } struct ucl_object *value = ucl_evaluate(scope, ucl_list_nth(args, 1)); + UCL_RET_IF_ERROR(value); - ucl_scope_put(root_scope, sym->symbol, value); + ucl_scope_put(scope, sym->symbol, value); return value; } diff --git a/test/test_e2e.c b/test/test_e2e.c index c3dc701..623ea5a 100644 --- a/test/test_e2e.c +++ b/test/test_e2e.c @@ -152,6 +152,10 @@ void test_setq(void) { } void test_setq_from_function(void) { + response = eval("(setq bar 1)"); + + TEST_ASSERT_OBJ_INT_V(response, 1); + response = eval("(defun foo (a) (setq bar a))"); TEST_ASSERT_OBJ_SYMBOL_V(response, "foo"); @@ -162,7 +166,7 @@ void test_setq_from_function(void) { response = eval("bar"); - TEST_ASSERT_OBJ_INT_V(response, 2); + TEST_ASSERT_OBJ_INT_V(response, 1); } void test_lambda(void) {