Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove ambiguity from "not safe to write" compiler error message #4299

Merged
merged 12 commits into from
Jan 17, 2023
12 changes: 12 additions & 0 deletions src/libponyc/expr/operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ bool expr_assign(pass_opt_t* opt, ast_t* ast)
}
}

if(ast_child(left) != NULL)
{
ast_error(opt->check.errors, ast,
"not safe to write right side to left side");
ast_error_continue(opt->check.errors, r_type, "right side type: %s",
ast_print_type(r_type));
ast_error_continue(opt->check.errors, ast_child(left), "left side type: %s",
ast_print_type(ast_type(ast_child(left))));
ast_free_unattached(wl_type);
return false;
}

ast_error(opt->check.errors, ast,
"not safe to write right side to left side");
ast_error_continue(opt->check.errors, wl_type, "right side type: %s",
Expand Down
18 changes: 18 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,21 @@ TEST_F(BadPonyTest, CantAssignErrorExpression)
TEST_ERRORS_1(src,
"right side must be something that can be assigned")
}

TEST_F(BadPonyTest, NotSafeToWrite)
{
// From issue #4290
const char* src =
"class Foo\n"
"class X\n"
"var foo: Foo ref = Foo\n"

"actor Main\n"
"new create(env: Env) =>\n"
"let x = X\n"
"let foo: Foo ref = Foo\n"
"x.foo = foo";

TEST_ERRORS_1(src,
"not safe to write right side to left side")
}