Skip to content

Commit

Permalink
Fix compiler crash introduced in #4283 (#4288)
Browse files Browse the repository at this point in the history
Fixes a missed case in #4283 (arrow types). Instead of displaying
an error message, the user who was attempting to do an unsafe
mutation of a val was greeted by a compiler crash.

Fixes #4287
  • Loading branch information
SeanTAllen committed Dec 30, 2022
1 parent a3ec45d commit 2d33583
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .release-notes/4287.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Fix compiler crash when attempting to mutate a val field

In Pony 0.52.4 we fixed an unsoundness bug that had been introduced over the summer. While fixing that bug, an error case was missed and as a result, a compiler crash was created where an error message should have been generated.

We've fixed the crash and it now displays a "left side is immutable" error message.
4 changes: 4 additions & 0 deletions src/libponyc/type/safeto.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ bool safe_to_mutate(ast_t* ast)
AST_GET_CHILDREN(ast, left, right);
ast_t* l_type = ast_type(left);

// Any viewpoint adapted type will not be safe to write to.
if(ast_id(l_type) != TK_NOMINAL)
return false;

token_id l_cap = cap_single(l_type);
return cap_mutable(l_cap);
}
Expand Down
13 changes: 13 additions & 0 deletions test/libponyc/cap_safety.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,16 @@ TEST_F(CapSafetyTest, WriteValToIso)

TEST_COMPILE(src);
}

TEST_F(CapSafetyTest, NoWriteArrow)
{
const char* src =
"actor Main"
" var f: U64 = 1"
" new create(env: Env) =>"
" _start()"
" fun _start() =>"
" f = 2";

TEST_ERROR(src);
}

0 comments on commit 2d33583

Please sign in to comment.