Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot assign to array[index] #70

Closed
Akuli opened this issue Jan 16, 2023 · 0 comments
Closed

cannot assign to array[index] #70

Akuli opened this issue Jan 16, 2023 · 0 comments

Comments

@Akuli
Copy link
Owner

Akuli commented Jan 16, 2023

declare malloc(size: int) -> void*

def main() -> int:
    x: int* = malloc(111)
    x[1] = 8

Expected result: no error

Actual result:

akuli@Akuli-ThinkPad:~/jou$ ./jou asd3.jou
compiler error in file "asd3.jou", line 5: cannot assign to a newly calculated value

Attempting this quick and dirty fix...

diff --git a/src/typecheck.c b/src/typecheck.c
index 127a013..be7c777 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -569,12 +569,12 @@ static void typecheck_statement(TypeContext *ctx, const AstStatement *stmt)
                         break;
                     case AST_EXPR_GET_FIELD:
                     case AST_EXPR_DEREF_AND_GET_FIELD:
+                    default:
                         snprintf(
                             errmsg, sizeof errmsg,
                             "cannot assign a value of type FROM into field '%s' of type TO",
                             targetexpr->data.field.fieldname);
                         break;
-                    default: assert(0);
                 }
                 const ExpressionTypes *targettypes = typecheck_expression(ctx, targetexpr);
                 typecheck_expression_with_implicit_cast(ctx, valueexpr, targettypes->type, errmsg);

...gives a new error:

akuli@Akuli-ThinkPad:~/jou$ ./jou asd3.jou
compiler error in file "asd3.jou", line 5: cannot assign to a newly calculated value
@Akuli Akuli closed this as completed in 8c45430 Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant