Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better error message for assigning to ro variable
If possible, include the name of the variable that was assigned to.
  • Loading branch information
MasterDuke17 committed Nov 29, 2016
1 parent 5163e8a commit 3982b20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/vm/jvm/runtime/org/perl6/rakudo/RakudoContainerSpec.java
Expand Up @@ -41,8 +41,15 @@ public void store(ThreadContext tc, SixModelObject cont, SixModelObject value) {
rw = tc.native_i;
}
if (rw == 0)
throw ExceptionHandling.dieInternal(tc,
"Cannot assign to a readonly variable or a value");
if (desc != null) {
desc.get_attribute_native(tc, gcx.ContainerDescriptor, "$!name", RakOps.HINT_CD_NAME);
throw ExceptionHandling.dieInternal(tc,
"Cannot assign to a readonly variable (" + tc.native_s + ") or a value");
}
else {
throw ExceptionHandling.dieInternal(tc,
"Cannot assign to a readonly variable or a value");
}

if (value.st.WHAT == gcx.Nil) {
value = desc.get_attribute_boxed(tc,
Expand Down
5 changes: 4 additions & 1 deletion src/vm/moar/ops/container.c
Expand Up @@ -79,7 +79,10 @@ static void rakudo_scalar_store(MVMThreadContext *tc, MVMObject *cont, MVMObject
if (rcd && IS_CONCRETE(rcd))
rw = rcd->rw;
if (!rw)
MVM_exception_throw_adhoc(tc, "Cannot assign to a readonly variable or a value");
if (rcd && IS_CONCRETE(rcd) && rcd->name)
MVM_exception_throw_adhoc(tc, "Cannot assign to a readonly variable (%s) or a value", MVM_string_utf8_encode_C_string(tc, rcd->name));
else
MVM_exception_throw_adhoc(tc, "Cannot assign to a readonly variable or a value");

/* Handle Nil and type-checking. */
if (!obj) {
Expand Down

0 comments on commit 3982b20

Please sign in to comment.