From ec7936226a2e82b10bc1fdac132a1d26d178dbcd Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 23 Jun 2024 10:54:21 +0200 Subject: Add constrain to let parsing either type or value must be present --- src/main.c | 2 +- src/parser.c | 6 ++++++ tests/variables.bad | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 2c2cc2d..2d2e04d 100644 --- a/src/main.c +++ b/src/main.c @@ -442,7 +442,7 @@ analyzer_typecheck(Analyzer *a, Node *node, Scope *scope) { case NODE_NUM_INT: case NODE_NUM_UINT: { // TODO: Check if the terminal correspond to an integer numeric type. - printf("DING\n"); + // printf("DING\n"); } break; case NODE_LET: { // Check the value first to avoid recursive symbol usage. diff --git a/src/parser.c b/src/parser.c index 7864264..9079df9 100644 --- a/src/parser.c +++ b/src/parser.c @@ -521,6 +521,12 @@ parse_keyword(Parser *parser) { parse_expr(parser, PREC_LOW); node->var_val = array_pop(parser->nodes); } + + if (node->var_type == NULL && node->var_val == NULL) { + parse_emit_err(parser, prev, + cstr("variable declaration must include type or " + "value information")); + } } break; case TOK_SET: { node = node_alloc(parser, NODE_SET, prev); diff --git a/tests/variables.bad b/tests/variables.bad index 990685f..bb449f6 100644 --- a/tests/variables.bad +++ b/tests/variables.bad @@ -1,6 +1,6 @@ ; Basic variable declaration with and without default values. The type could be ; inferred, but can also be manually specified. -let a +let a: str let b: f64 let c:u64 = 20 -- cgit v1.2.1