summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test.toc6
-rw-r--r--types.c29
2 files changed, 27 insertions, 8 deletions
diff --git a/test.toc b/test.toc
index c2a951c..e5ca1fa 100644
--- a/test.toc
+++ b/test.toc
@@ -2,10 +2,10 @@ io ::= nms {
#include "std/io.toc";
};
-p ::= struct(x::Type) {
- y:int;
+p ::= struct(x::Type,y::=3) {
+ b:int;
};
main ::= fn() {
z:p(int);
-for z := 1..100 {z:=12;}
+x:[z.y]z.x;
}; \ No newline at end of file
diff --git a/types.c b/types.c
index cd61025..5eac674 100644
--- a/types.c
+++ b/types.c
@@ -2337,12 +2337,31 @@ static bool types_expr(Typer *tr, Expression *e) {
e->binary.dot.field = f;
}
}
-
if (!is_field) {
- char *member = ident_to_str(rhs->ident);
- char *struc = type_to_str(struct_type);
- err_print(e->where, "%s is not a member of structure %s.", member, struc);
- return false;
+ Declaration *param = NULL;
+ int ident_idx;
+ arr_foreach(struct_type->struc->params, Declaration, p) {
+ ident_idx = 0;
+ arr_foreach(p->idents, Identifier, ident) {
+ if (ident_eq(*ident, rhs->ident)) {
+ param = p;
+ goto dblbreak_dot;
+ }
+ ++ident_idx;
+ }
+ }
+ dblbreak_dot:
+ if (!param) {
+ char *member = ident_to_str(rhs->ident);
+ char *struc = type_to_str(struct_type);
+ err_print(e->where, "%s is not a member of structure %s.", member, struc);
+ return false;
+ }
+ /* replace with parameter value */
+ e->kind = EXPR_VAL;
+ e->val = *decl_val_at_index(param, ident_idx);
+ *t = *decl_type_at_index(param, ident_idx);
+ break;
}
} else if (struct_type->kind == TYPE_SLICE || struct_type->kind == TYPE_ARR) {
if (!ident_eq_str(rhs->ident, "len")) {