Skip to content

Commit

Permalink
Associative assignment to non-existent attribute doesn't die
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanstowe committed Sep 21, 2017
1 parent 6ca8bba commit 40e9f8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/META6.pm
Expand Up @@ -123,7 +123,9 @@ role AutoAssoc {
}

method ASSIGN-KEY($key, \value) {
self!json-name-to-attibute($key).set_value(self, value)
if self!json-name-to-attibute($key) -> $attr {
$attr.set_value(self, value)
}
}

method !json-name-to-attibute($json-name) {
Expand Down
2 changes: 2 additions & 0 deletions t/050-assoc.t
Expand Up @@ -22,6 +22,8 @@ is $obj<version perl>, '0.0.1 6', 'Hash get list of keys';
is $obj<version>:exists, True, 'Hash key exists';
is $obj<isnthere>:exists, False, 'Hash key does not exist';

lives-ok { $obj<isnthere> = 'foo' }, "set non-existent attribute";

$obj<version> = v0.0.2;
is $obj<version>, '0.0.2', 'Hash set good version';

Expand Down

0 comments on commit 40e9f8f

Please sign in to comment.