Skip to content

Commit

Permalink
error properly when trying to deref a scalar as an array with $var(fo…
Browse files Browse the repository at this point in the history
…o) syntax.
  • Loading branch information
coke committed Jul 4, 2010
1 parent 09e46d1 commit 0c50088
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/Partcl/Actions.pm
Expand Up @@ -164,16 +164,24 @@ sub concat_atoms(@atoms) {
method variable:sym<normal>($/) {
if $<key> {
# Array access
# XXX needs error handling.
my $variable := PAST::Var.new( :scope<keyed>,
PAST::Var.new( :name<lexpad>, :scope<register> ),
~$<identifier>
);
make PAST::Var.new( :scope<keyed>,
$variable,
~$<key>[0]
);
make PAST::Op.new( :pasttype<if>,
PAST::Op.new( :pirop<iseq__iss>,
PAST::Op.new( :pirop<typeof__sP>, $variable),
PAST::Val.new( :value<TclArray>)
),
PAST::Var.new( :scope<keyed>,
$variable,
~$<key>[0]
),
PAST::Op.new( :pasttype<call>, :name<error>,
"can't read \"$<identifier>({$<key>[0]})\": variable isn't array"
)
)
}
else {
# Scalar
Expand Down
2 changes: 1 addition & 1 deletion t/tcl_var_subst.t
Expand Up @@ -37,7 +37,7 @@ eval_is {
catch {unset a}
set a 2
set b $a(b)
} {can't read "a(b)": variable isn't array} {try to use scalar as array} {TODO NQPRX}
} {can't read "a(b)": variable isn't array} {try to use scalar as array}

eval_is {
catch {unset a}
Expand Down

0 comments on commit 0c50088

Please sign in to comment.