From ce130e8da7f41400a9ff45b3d30d34930ce31feb Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 20 Nov 2019 12:27:29 -0500 Subject: fixed problem with type params --- copy.c | 8 +++++--- test.toc | 12 ++++++------ types.c | 2 ++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/copy.c b/copy.c index 9f1acac..0cc5f4d 100644 --- a/copy.c +++ b/copy.c @@ -45,7 +45,7 @@ static void copy_val(Copier *c, Value *out, Value *in, Type *t) { } static void copy_type(Copier *c, Type *out, Type *in) { - assert(!(in->flags & TYPE_IS_RESOLVED)); + /* needs to handle resolved and unresolved types properly */ *out = *in; switch (in->kind) { case TYPE_BUILTIN: @@ -71,8 +71,10 @@ static void copy_type(Copier *c, Type *out, Type *in) { } } break; case TYPE_ARR: - out->arr.n_expr = allocr_malloc(c->allocr, sizeof *out->arr.n_expr); - copy_expr(c, out->arr.n_expr, in->arr.n_expr); + if (!(in->flags & TYPE_IS_RESOLVED)) { + out->arr.n_expr = allocr_malloc(c->allocr, sizeof *out->arr.n_expr); + copy_expr(c, out->arr.n_expr, in->arr.n_expr); + } out->arr.of = allocr_malloc(c->allocr, sizeof *out->arr.of); copy_type(c, out->arr.of, in->arr.of); break; diff --git a/test.toc b/test.toc index 1fdab47..bc26708 100644 --- a/test.toc +++ b/test.toc @@ -1,7 +1,7 @@ -// puti @= fn(x: int) { -// #C("printf(\"%ld\\n\", (long)x); -// "); -// }; +puti @= fn(x: int) { + #C("printf(\"%ld\\n\", (long)x); +"); +}; // putf @= fn(x: float) { // #C("printf(\"%f\\n\", (double)x); // "); @@ -10,8 +10,8 @@ main @= fn() { - g(int); - g(); + puti(g(int)); + puti(g()); }; g @= fn(t @= int) int { diff --git a/types.c b/types.c index 784c218..a29c9d7 100644 --- a/types.c +++ b/types.c @@ -1606,6 +1606,8 @@ static bool types_expr(Typer *tr, Expression *e) { break; } case EXPR_TYPE: + if (!type_resolve(tr, &e->typeval, e->where)) + return false; t->kind = TYPE_TYPE; break; case EXPR_VAL: -- cgit v1.2.3