diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-04-01 14:51:20 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-04-01 14:51:20 +0300 |
| commit | 4642bedb436981e92e3312f06bfcb2eb34074596 (patch) | |
| tree | cc5bf868a391c9880b9917eed44b20e4df535d1d /src/actualize.c | |
| parent | 0132be5b71f3fe161b2fcda201c945d30bd8d1a5 (diff) | |
| download | ek-4642bedb436981e92e3312f06bfcb2eb34074596.tar.gz ek-4642bedb436981e92e3312f06bfcb2eb34074596.zip | |
disallow certain kinds of types in templates
Diffstat (limited to 'src/actualize.c')
| -rw-r--r-- | src/actualize.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/actualize.c b/src/actualize.c index 0c7a378..4d1d449 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -21,6 +21,7 @@ enum act_flags { ACT_IN_SWITCH = (1 << 1), ACT_ONLY_TYPES = (1 << 2), ACT_HAS_RETURN = (1 << 3), + ACT_REQUIRE_FULLY_QUALIFIED = (1 << 4), }; struct act_state { @@ -998,6 +999,7 @@ static int actualize_proc(struct act_state *state, * think */ struct act_state new_state = {0}; new_state.cur_proc = actual; + act_set_flags(&new_state, ACT_REQUIRE_FULLY_QUALIFIED); /* actualize body */ ret |= actualize(&new_state, sign->scope, actual->_proc.body); if (!act_flags(&new_state, ACT_HAS_RETURN)) { @@ -1358,7 +1360,23 @@ static int actualize_type(struct act_state *state, if (actualize(state, scope, types)) EXIT_ACT(-1); - /* TODO: check that all params are fully qualified */ + while (types) { + if (!primitive_type(types)) { + semantic_error(scope->fctx, types, + "only primitive types allowed in template initialization"); + EXIT_ACT(-1); + } + + if (act_flags(state, ACT_REQUIRE_FULLY_QUALIFIED)) { + if (!fully_qualified(types)) { + semantic_error(scope->fctx, types, + "context requires fully qualified types"); + EXIT_ACT(-1); + } + } + types = types->next; + } + break; } @@ -1611,14 +1629,26 @@ static int init_struct(struct act_state *state, struct scope *scope, struct ast_node *actual_type(struct ast_node *type) { assert(type->node_type == AST_TYPE); - if (type->_type.kind == AST_TYPE_ALIAS) - return actual_type(type->_type.alias.actual); + if (type->_type.kind == AST_TYPE_ALIAS) { + if (type->_type.alias.actual) + return actual_type(type->_type.alias.actual); - if (type->_type.kind == AST_TYPE_TEMPLATE) - return actual_type(type->_type.template.actual); + return type; + } - if (type->_type.kind == AST_TYPE_TYPEOF) - return actual_type(type->_type.typeo.actual); + if (type->_type.kind == AST_TYPE_TEMPLATE) { + if (type->_type.template.actual) + return actual_type(type->_type.template.actual); + + return type; + } + + if (type->_type.kind == AST_TYPE_TYPEOF) { + if (type->_type.typeo.actual) + return actual_type(type->_type.typeo.actual); + + return type; + } return type; } |
