Skip to content

Commit

Permalink
[QAST::Block] only create hashes when .symbol sets
Browse files Browse the repository at this point in the history
When the getter variant of .symbol is used, it now returns an
undefined value, rather than autovivify a hash for it.
  • Loading branch information
Carl Masak committed May 25, 2012
1 parent 9e3e240 commit b0b24cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/QAST/Block.nqp
Expand Up @@ -27,9 +27,11 @@ class QAST::Block is QAST::Node {
}

method symbol($name, *%attrs) {
%!symbol{$name} := %!symbol{$name} // {};
for %attrs {
%!symbol{$name}{$_.key} := $_.value;
if %attrs {
%!symbol{$name} := %!symbol{$name} // {};
for %attrs {
%!symbol{$name}{$_.key} := $_.value;
}
}
%!symbol{$name}
}
Expand Down
6 changes: 6 additions & 0 deletions t/qast/qast.t
Expand Up @@ -741,3 +741,9 @@ is_qast(
my %hash := $block.symbol('slug');
ok(%hash<food> eq 'cheeseburger', 'QAST::Block.symbol existing attributes don\'t disappear');
}

{
my $block := QAST::Block.new();
my $missing := $block.symbol('sabre-toothed tiger');
ok(!pir::defined($missing), 'QAST::Block.symbol on a nonexistent key returns an undefined value');
}

0 comments on commit b0b24cf

Please sign in to comment.