aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-23 10:54:21 +0200
committerBad Diode <bd@badd10de.dev>2024-06-23 10:54:21 +0200
commitec7936226a2e82b10bc1fdac132a1d26d178dbcd (patch)
tree7b0ed4cf889992bcb5def1df18b062159a9ee69b
parent8931a6f22b9586c62082c525ec8b6de62c7de5d5 (diff)
downloadbdl-ec7936226a2e82b10bc1fdac132a1d26d178dbcd.tar.gz
bdl-ec7936226a2e82b10bc1fdac132a1d26d178dbcd.zip
Add constrain to let parsing either type or value must be present
-rw-r--r--src/main.c2
-rw-r--r--src/parser.c6
-rw-r--r--tests/variables.bad2
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) {
442 case NODE_NUM_INT: 442 case NODE_NUM_INT:
443 case NODE_NUM_UINT: { 443 case NODE_NUM_UINT: {
444 // TODO: Check if the terminal correspond to an integer numeric type. 444 // TODO: Check if the terminal correspond to an integer numeric type.
445 printf("DING\n"); 445 // printf("DING\n");
446 } break; 446 } break;
447 case NODE_LET: { 447 case NODE_LET: {
448 // Check the value first to avoid recursive symbol usage. 448 // 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) {
521 parse_expr(parser, PREC_LOW); 521 parse_expr(parser, PREC_LOW);
522 node->var_val = array_pop(parser->nodes); 522 node->var_val = array_pop(parser->nodes);
523 } 523 }
524
525 if (node->var_type == NULL && node->var_val == NULL) {
526 parse_emit_err(parser, prev,
527 cstr("variable declaration must include type or "
528 "value information"));
529 }
524 } break; 530 } break;
525 case TOK_SET: { 531 case TOK_SET: {
526 node = node_alloc(parser, NODE_SET, prev); 532 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 @@
1; Basic variable declaration with and without default values. The type could be 1; Basic variable declaration with and without default values. The type could be
2; inferred, but can also be manually specified. 2; inferred, but can also be manually specified.
3let a 3let a: str
4let b: f64 4let b: f64
5let c:u64 = 20 5let c:u64 = 20
6 6