diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -11,6 +11,7 @@ | |||
11 | // are assigning a struct literal, not just a symbol. | 11 | // are assigning a struct literal, not just a symbol. |
12 | // TODO: nested structs | 12 | // TODO: nested structs |
13 | // TODO: unions | 13 | // TODO: unions |
14 | // TODO: match deconstruct structs | ||
14 | 15 | ||
15 | typedef enum ExecMode { | 16 | typedef enum ExecMode { |
16 | RUN_NORMAL, | 17 | RUN_NORMAL, |
@@ -507,8 +508,17 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
507 | return node->type; | 508 | return node->type; |
508 | } break; | 509 | } break; |
509 | case NODE_SET: { | 510 | case NODE_SET: { |
510 | type_inference(a, node->var_name, scope); | 511 | Type name = type_inference(a, node->var_name, scope); |
511 | type_inference(a, node->var_val, scope); | 512 | Type val = type_inference(a, node->var_val, scope); |
513 | if (!str_eq(name, val)) { | ||
514 | eprintln( | ||
515 | "%s:%d:%d: error: type mismatch, trying to assing " | ||
516 | "%s" | ||
517 | " to a variable of type %s", | ||
518 | a->file_name, node->line, node->col, | ||
519 | val, name); | ||
520 | return cstr(""); | ||
521 | } | ||
512 | node->type = cstr("nil"); | 522 | node->type = cstr("nil"); |
513 | return node->type; | 523 | return node->type; |
514 | } break; | 524 | } break; |
@@ -816,7 +826,7 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
816 | } | 826 | } |
817 | node->next->type = cstr("int"); | 827 | node->next->type = cstr("int"); |
818 | node->type = type->val; | 828 | node->type = type->val; |
819 | return node->type; | 829 | return node->next->type; |
820 | } | 830 | } |
821 | 831 | ||
822 | StructMap *s = find_struct(scope, type->val); | 832 | StructMap *s = find_struct(scope, type->val); |