summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-11-20 12:27:29 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-11-20 12:27:29 -0500
commitce130e8da7f41400a9ff45b3d30d34930ce31feb (patch)
tree1898ede373d2adf7ad63928e92be7f20f5fcbec2
parentb905ea0f51cba69837643717182982dd93cd3f0d (diff)
fixed problem with type params
-rw-r--r--copy.c8
-rw-r--r--test.toc12
-rw-r--r--types.c2
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: