summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--parse.c5
-rw-r--r--test.toc14
-rw-r--r--types.c4
4 files changed, 16 insertions, 11 deletions
diff --git a/main.c b/main.c
index f08d5d9..6336fad 100644
--- a/main.c
+++ b/main.c
@@ -8,10 +8,8 @@
/*
TODO:
-make sure varargs[i] isn't an lvalue
-make sure you can't have a variadic function pointer
-make sure varargs works with inference
passing varargs variable to varargs function
+make sure varargs works with inference
#foreign variadic fns
EXPR_VALs don't always need temp variables
where
diff --git a/parse.c b/parse.c
index 1430d2e..9413d6a 100644
--- a/parse.c
+++ b/parse.c
@@ -2200,7 +2200,10 @@ static Status parse_expr(Parser *p, Expression *e, Token *end) {
}
success:
e->where.end = t->token;
- assert(t->token == end);
+ if (t->token != end) {
+ tokr_err(t, "Did not expect this stuff after expression. Did you forget a semicolon?");
+ return false;
+ }
if (e->kind == EXPR_FN) {
e->fn->where = e->where;
diff --git a/test.toc b/test.toc
index 53efe0d..c12a1f7 100644
--- a/test.toc
+++ b/test.toc
@@ -1,19 +1,19 @@
#include "std/io.toc";
-s ::= struct(x::..) {
-};
-
-f ::= fn(x : ..) int {
+g ::= fn(x : ..) int {
total := 0;
- for _, i := x {
- total += i * (x[0] as int);
+ for e, i := x {
+ total += i * (e as int);
}
total
};
+f ::= fn(x : ..) int {
+ g(x)
+};
main ::= fn() {
- puti(f(5));
+ puti(g(5));
puti(f(5,6));
diff --git a/types.c b/types.c
index e43e6f8..e181476 100644
--- a/types.c
+++ b/types.c
@@ -303,6 +303,10 @@ static Status expr_must_lval(Expression *e) {
case BINARY_AT_INDEX:
if (!expr_must_lval(e->binary.lhs))
return false;
+ if (type_is_builtin(&e->binary.lhs->type, BUILTIN_VARARGS)) {
+ err_print(e->where, "Cannot set or take address of vararg.");
+ return false;
+ }
return true;
case BINARY_DOT: return true;
default: break;