diff options
| -rw-r--r-- | src/actualize.c | 41 | ||||
| -rw-r--r-- | tests/struct_trait_cont/source.mk | 1 | ||||
| -rw-r--r-- | tests/struct_trait_cont/struct_trait_cont.ek | 20 | ||||
| -rw-r--r-- | tests/struct_trait_cont/vgcore.43898 | bin | 0 -> 6836224 bytes |
4 files changed, 47 insertions, 15 deletions
diff --git a/src/actualize.c b/src/actualize.c index 409480b..7f590c3 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -632,20 +632,15 @@ static int replace_id(struct ast *body, struct ast *id, return ast_visit(_replace_id, NULL, body, pair); } -static int implements(struct type *trait, struct type *type) +static int implements_chain(struct ast *trait_def, struct ast *def) { - assert(trait->d); - struct ast *trait_def = trait->d; - assert(trait_def->k == AST_TRAIT_DEF); - - /* empty traits are implemented implicitly */ - if (!trait_body(trait_def)) - return 1; - - assert(type->d); - struct ast *def = type->d; - assert(def->k == AST_STRUCT_DEF); - struct ast *body = struct_body(def); + struct ast *body = NULL; + if (def->k == AST_STRUCT_DEF) + body = struct_body(def); + else if (def->k == AST_STRUCT_CONT_DEF) + body = struct_cont_body(def); + else + abort(); foreach_node(n, body) { if (n->k != AST_TYPE_EXPAND) @@ -661,10 +656,26 @@ static int implements(struct type *trait, struct type *type) return 1; } - /** @todo look up possible continuations for type */ + if (def->chain) + return implements_chain(trait_def, def->chain); + return 0; } +static int implements(struct type *trait, struct type *type) +{ + assert(trait->d); + struct ast *trait_def = trait->d; + assert(trait_def->k == AST_TRAIT_DEF); + + /* empty traits are implemented implicitly */ + if (!trait_body(trait_def)) + return 1; + + assert(type->d); + return implements_chain(trait_def, type->d); +} + static int should_implement_list(struct scope *scope, struct ast *params, struct src_loc loc, struct type *types) { @@ -2522,7 +2533,7 @@ static int actualize_init(struct act_state *state, vec_sort(&struct_members, (vec_comp_t)init_sort); if (vec_len(&init_args) != vec_len(&struct_members)) { - semantic_error(scope->fctx, node, "expected %zs args, got %zs", + semantic_error(scope->fctx, node, "expected %zu args, got %zu", vec_len(&struct_members), vec_len(&init_args)); goto err; diff --git a/tests/struct_trait_cont/source.mk b/tests/struct_trait_cont/source.mk new file mode 100644 index 0000000..b82c0b9 --- /dev/null +++ b/tests/struct_trait_cont/source.mk @@ -0,0 +1 @@ +SIMPLE += struct_trait_cont diff --git a/tests/struct_trait_cont/struct_trait_cont.ek b/tests/struct_trait_cont/struct_trait_cont.ek new file mode 100644 index 0000000..f8e05c5 --- /dev/null +++ b/tests/struct_trait_cont/struct_trait_cont.ek @@ -0,0 +1,20 @@ +define a[] { + a(); +} + +typedef struct {} +continue struct { + a![]; + a(){} +} + +typedef struct2[a T] { + T elem; +} + +main() +{ + mut p = struct2![struct]{ + .elem = struct!{} + }; +} diff --git a/tests/struct_trait_cont/vgcore.43898 b/tests/struct_trait_cont/vgcore.43898 Binary files differnew file mode 100644 index 0000000..c12d319 --- /dev/null +++ b/tests/struct_trait_cont/vgcore.43898 |
