commit 30ef36d3dbffce202bfa3d6e6385283833abb480
parent d496fab1ba3f530197e29ec10e285344c5e3538b
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Mon, 13 Dec 2021 16:07:06 -0600
type check proc declarations
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
@@ -177,7 +177,6 @@ typecheck(struct block items)
error(decl->start->line, decl->start->col, "expected string expression for string declaration");
break;
- // !!!!! FIXME: CHECK PARAMETER TYPES !!!!!!
case TYPE_PROC:
expr = &exprs.data[decl->val];
if (expr->class != C_PROC)
@@ -185,6 +184,11 @@ typecheck(struct block items)
if (expr->d.proc.params.len != type->d.typelist.len)
error(decl->start->line, decl->start->col, "procedure expression takes %u parameters, but declaration has type which takes %u", expr->d.proc.params.len, type->d.typelist.len);
+
+ for (size_t j = 0; j < expr->d.proc.params.len; j++) {
+ if (expr->d.proc.params.data[j].type != type->d.typelist.data[j])
+ error(decl->start->line, decl->start->col, "unexpected type for parameter %u in procedure declaration", j);
+ }
break;
default:
error(decl->start->line, decl->start->col, "unknown decl type");
diff --git a/test/proc_type_mismatch.fail.nooc b/test/proc_type_mismatch.fail.nooc
@@ -0,0 +1,8 @@
+let exit proc(str) = proc(code i64) {
+ syscall(60, code)
+ return
+}
+
+let main proc = proc {
+ exit(0)
+}