Skip to content

Commit

Permalink
- Fixed the hard-coded arrays declared using a syntax-sugar shortcut,…
Browse files Browse the repository at this point in the history
… such as %w(...)

Example:
	{
	    var arr = %w(a b c);    # new array at each iteration
	    arr.append('d');
	    say arr;		    # prints: ["a", "b", "c", "d"] each time
	} * 2;

- The arrays are now re-created on each iteration.
  • Loading branch information
trizen committed Sep 7, 2015
1 parent 0b94d30 commit 8f6e9e7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/Sidef/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1433,16 +1433,16 @@ package Sidef::Parser {
my $strings = $self->get_quoted_words(code => $opt{code});

if ($type eq 'w' or $type eq '<') {
return Sidef::Types::Array::Array->new(map { Sidef::Types::String::String->new(s{\\(?=[\\#\s])}{}gr) }
@{$strings});
return Sidef::Types::Array::HCArray->new(map { Sidef::Types::String::String->new(s{\\(?=[\\#\s])}{}gr) }
@{$strings});
}
elsif ($type eq 'i') {
return Sidef::Types::Array::Array->new(map { Sidef::Types::Number::Number->new_int(s{\\(?=[\\#\s])}{}gr) }
@{$strings});
return Sidef::Types::Array::HCArray->new(
map { Sidef::Types::Number::Number->new_int(s{\\(?=[\\#\s])}{}gr) } @{$strings});
}
elsif ($type eq 'n') {
return Sidef::Types::Array::Array->new(map { Sidef::Types::Number::Number->new(s{\\(?=[\\#\s])}{}gr) }
@{$strings});
return Sidef::Types::Array::HCArray->new(map { Sidef::Types::Number::Number->new(s{\\(?=[\\#\s])}{}gr) }
@{$strings});
}

my ($inline_expression, @objs);
Expand All @@ -1457,7 +1457,7 @@ package Sidef::Parser {
return (
$inline_expression
? Sidef::Types::Array::HCArray->new(map { {self => $_} } @objs)
: Sidef::Types::Array::Array->new(@objs)
: Sidef::Types::Array::HCArray->new(@objs)
);
}

Expand Down

0 comments on commit 8f6e9e7

Please sign in to comment.