From 7be9a9ef0ee1f8ba475637301dcfefc4a7bf688c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 11 Oct 2022 14:20:35 +0200 Subject: [PATCH] Fix assignment type resolution --- README.md | 1 + core_main.cpp | 1 + core_typechecking.cpp | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f8db428..ca00d6e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ main :: (): int * **Debuggers**(Visual Studio, Remedybg) **fully work** with the language, you can step through the program * **No external dependencies**, you just setup clang and call build.bat +* **No heap allocation** during lifetime of the compiler * Compiles to C code, in the future it will also compile to bytecode and hopefully a raw x64 executable * Very strict Go like type system with untyped literals * **Order independent declarations** diff --git a/core_main.cpp b/core_main.cpp index c842ada..52c92dc 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -7,6 +7,7 @@ Current: - [ ] Typeof operator - [ ] Test and bulletproof any, slices +- [ ] Need tests that make sure stuff errors out Memory: - [ ] Redesign Type map to use List and reduce wasting space diff --git a/core_typechecking.cpp b/core_typechecking.cpp index db65b38..bc5796f 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1225,8 +1225,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str if(!left.is_lvalue) compiler_error(node->pos, "Assigning to rvalue"); Operand right = resolve_expr(node->right, AST_CANT_BE_NULL, 0, field_access_scope); - convert_untyped_to_typed(node->pos, &right.value, left.type); - if(left.type != right.type) compiler_error(node->pos, "Can't assign value when left is %Q and right is %Q", typestring(left.type), typestring(right.type)); + // @warning: Could be buggy, previously we strictly matched if types are exact + // need to test this with slices and stuff + make_sure_value_is_compatible_with_type(node->pos, &right, left.type, TYPE_AND_EXPR_REQUIRED); node->resolved_type = right.type; try_propagating_resolved_type_to_untyped_literals(node->left, node->resolved_type, node->right->resolved_type);