summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test.toc78
-rw-r--r--types.c5
2 files changed, 47 insertions, 36 deletions
diff --git a/test.toc b/test.toc
index c8e20be..e8f19ce 100644
--- a/test.toc
+++ b/test.toc
@@ -1,45 +1,51 @@
-// 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);
+// // ");
+// // };
+
+// Arr @= fn (t @ Type) Type {
+// struct {
+// data : t;
+// // len, cap : u64;
+// }
// };
-// putf @= fn(x: float) {
-// #C("printf(\"%f\\n\", (double)x);
-// ");
+
+// // todo: test that t @ type doesn't cause problems
+// arr_add @= fn(t @ Type, a : &Arr(t)) {
+// // if a.len >= a.cap {
+// // a.cap = a.cap * 2 + 2;
+// // new_data := new(t, a.cap);
+// // each i := 0..a.len {
+// // new_data[i] = a.data[i];
+// // }
+// // a.data = new_data;
+// // }
+// // a.data[a.len] = x;
+// // a.len += 1;
// };
-Arr @= fn (t @ Type) Type {
- struct {
- data : t;
- // len, cap : u64;
- }
-};
-// todo: test that t @ type doesn't cause problems
-arr_add @= fn(t @ Type, a : &Arr(t)) {
- // if a.len >= a.cap {
- // a.cap = a.cap * 2 + 2;
- // new_data := new(t, a.cap);
- // each i := 0..a.len {
- // new_data[i] = a.data[i];
- // }
- // a.data = new_data;
- // }
- // a.data[a.len] = x;
- // a.len += 1;
-};
+// main @= fn() {
+// // arr : Arr(int);
+// // // arr_add(int, &arr, 5);
+// // // arr_add(int, &arr, 10);
+// // // arr_add(int, &arr, 20);
+// // // each i := 0..arr.len - 1 {
+// // // puti(arr.data[i]);
+// // // }
+// };
+
+// // t @= fn(x @ Type) Type { struct { t: x; } };
+// // // pass the wrong thing to t, and the error is in the wrong place
+// // f @= fn(x: t(int)) {};
-main @= fn() {
-// arr : Arr(int);
-// // arr_add(int, &arr, 5);
-// // arr_add(int, &arr, 10);
-// // arr_add(int, &arr, 20);
-// // each i := 0..arr.len - 1 {
-// // puti(arr.data[i]);
-// // }
+f @= fn(t @ Type, x : t) {
};
-// t @= fn(x @ Type) Type { struct { t: x; } };
-// // pass the wrong thing to t, and the error is in the wrong place
-// f @= fn(x: t(int)) {}; \ No newline at end of file
+main @= fn() { f(int, 3); }; \ No newline at end of file
diff --git a/types.c b/types.c
index 4b6b5fb..835570a 100644
--- a/types.c
+++ b/types.c
@@ -197,6 +197,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags)
FnExpr *prev_fn = tr->fn;
FnExpr fn_copy;
+
if (!(flags & TYPE_OF_FN_NO_COPY_EVEN_IF_CONST) && fn_has_any_const_params(f)) {
Copier cop = copier_create(tr->allocr, tr->block);
copy_fn_expr(&cop, &fn_copy, f, false);
@@ -287,6 +288,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags)
} else {
f->ret_type.kind = TYPE_TUPLE;
f->ret_type.flags = TYPE_IS_RESOLVED;
+ f->ret_type.was_expr = NULL;
f->ret_type.tuple = NULL;
arr_foreach(f->ret_decls, Declaration, d) {
arr_foreach(d->idents, Identifier, i) {
@@ -1176,6 +1178,9 @@ static bool types_expr(Typer *tr, Expression *e) {
bool should_be_evald = arg_is_const(&new_args[i], fn_type->constness[i]);
if (should_be_evald) {
Value *arg_val = typer_arr_add(tr, &table_index.tuple);
+ printf("Evaluating expression: ");
+ print_location(new_args[i].where);
+
if (!eval_expr(tr->evalr, &new_args[i], arg_val)) {
if (tr->evalr->enabled) {
info_print(new_args[i].where, "(error occured while trying to evaluate compile-time argument, argument #%lu)", 1+(unsigned long)i);