Skip to content
Browse files

[QAST::Block] only create hashes when .symbol sets

When the getter variant of .symbol is used, it now returns an
undefined value, rather than autovivify a hash for it.
  • Loading branch information...
1 parent 9e3e240 commit b0b24cfd5744b3ee40c2b165f2d15d32b07d3f99 @masak masak committed May 25, 2012
Showing with 11 additions and 3 deletions.
  1. +5 −3 src/QAST/Block.nqp
  2. +6 −0 t/qast/qast.t
View
8 src/QAST/Block.nqp
@@ -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}
}
View
6 t/qast/qast.t
@@ -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.
Something went wrong with that request. Please try again.