nooc

nooc programming language compiler
git clone git://git.nihaljere.xyz/nooc
Log | Files | Refs | LICENSE

commit af471ce9faad92173994dd4d2183a38d09dcbcb4
parent bf837c7dd7ee04d8c06f17597b761382e8695da1
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Mon, 20 Dec 2021 18:22:57 -0600

check assignment expression for correct class instead of declaration

Diffstat:
Mmain.c | 5++---
Mtest/type.fail.nooc | 6++++--
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c @@ -273,29 +273,28 @@ typecheck(struct block *block) error(assgn->start->line, assgn->start->col, "typecheck: unknown name '%.*s'", assgn->s.len, assgn->s.data); type = &types.data[decl->type]; + expr = &exprs.data[assgn->val]; line = assgn->start->line; col = assgn->start->col; goto check; case ITEM_DECL: decl = &block->decls.data[item->idx]; type = &types.data[decl->type]; + expr = &exprs.data[decl->val]; line = decl->start->line; col = decl->start->col; check: switch (type->class) { case TYPE_I64: - expr = &exprs.data[decl->val]; if (expr->class != C_INT) error(line, col, "expected integer expression for integer declaration"); break; case TYPE_STR: - expr = &exprs.data[decl->val]; if (expr->class != C_STR) error(line, col, "expected string expression for string declaration"); break; case TYPE_PROC: - expr = &exprs.data[decl->val]; if (expr->class != C_PROC) error(line, col, "expected proc expression for proc declaration"); diff --git a/test/type.fail.nooc b/test/type.fail.nooc @@ -1,2 +1,4 @@ -let num i64 = 15 -num = "a string" +let main proc() = proc() { + let num i64 = 15 + num = "a string" +}