From b0b24cfd5744b3ee40c2b165f2d15d32b07d3f99 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Fri, 25 May 2012 22:45:56 +0200 Subject: [PATCH] [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. --- src/QAST/Block.nqp | 8 +++++--- t/qast/qast.t | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/QAST/Block.nqp b/src/QAST/Block.nqp index 8b6c45dfa8..9a69dabc06 100644 --- a/src/QAST/Block.nqp +++ b/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} } diff --git a/t/qast/qast.t b/t/qast/qast.t index cc9ad5d924..fb2080629c 100644 --- a/t/qast/qast.t +++ b/t/qast/qast.t @@ -741,3 +741,9 @@ is_qast( my %hash := $block.symbol('slug'); ok(%hash 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'); +}