[Pugs] Bugs

0 views
Skip to first unread message

Stevan Little

unread,
Mar 7, 2005, 6:08:21 PM3/7/05
to perl6-c...@perl.org
Autrijus and Co.

I have found another weird bug. It apprears to be a problem with the
way the return statement handles Array refs and Hash refs in scalar
context. I have some tests in t/op/sub_return_values.t which test the
array ref problem. I will try and flesh out the hash-ref tests in the
same file later tonight. But anyway here is a description of the bug.

The following code:
pugs -e 'sub foo { return [ 1, 2, 3 ] }; my $test = foo(); say
$test; say ref($test);'
will print out:
3
Int

While all of the following code:
pugs -e 'sub foo { [ 1, 2, 3 ] }; my $test = foo(); say $test; say
ref($test);'
pugs -e 'sub foo { return ( 1, 2, 3 ) }; my @test = foo(); say
@test; say ref(@test);'
pugs -e 'sub foo { return [ 1, 2, 3 ] }; my @test = foo(); say
@test; say ref(@test);'
will print out:
123
List

I also suspect that the same bug is causing this code:
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); return \%h;
}; my $test = foo(); say $test; say ref($test);'

to print out:
two2
Pair

because all of these (note the lack of return statement):
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); \%h; }; my
$test = foo(); say $test; say ref($test);'
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); %h; }; my
$test = foo(); say $test; say ref($test);'

will print out:
one 1
three 3
two 2
Hash

Then there is this code:
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); return %h; };
my %test = foo(); say %test; say ref(%test);'

which won't even compile. The error is spits out is:

Fail: cannot cast into [VPair]: VSub (Sub {isMulti = False, subName =
"&foo", subType = SubRoutine, subPad = [], subAssoc = "pre", subParams
= [Param {isInvocant = False, isSlurpy = True, isOptional = False,
isNamed = True, isLValue = False, paramName = "@_", paramContext =
"List", paramDefault = Val VUndef}], subReturns = "Any", subFun =
Statements [(Syn "sym" [Sym (Symbol {symScope = SMy, symName = "%h",
symExp = Syn "mval" [Var "%h",Syn "," [Syn "," [Syn "," [Syn "," [Syn
"," [Syn "cxt" [Val (VStr "Str"),App "&infix:~" [Val (VStr "one"),Val
(VStr "")] []],Val (VInt 1)],Syn "cxt" [Val (VStr "Str"),App "&infix:~"
[Val (VStr "two"),Val (VStr "")] []]],Val (VInt 2)],Syn "cxt" [Val
(VStr "Str"),App "&infix:~" [Val (VStr "three"),Val (VStr "")] []]],Val
(VInt 3)]]})],"-" (line 1, column 11)),(App "&return" [Var "%h"] [],"-"
(line 1, column 48))]})

I suspect this to might be a symptom of the above bug, but I cannot
tell for sure.

Anyway, Hope this helps out some.

- Steve

Joost Diepenmaat

unread,
Mar 8, 2005, 6:41:40 AM3/8/05
to perl6-c...@perl.org
On Mon, Mar 07, 2005 at 06:08:21PM -0500, Stevan Little wrote:
> Autrijus and Co.
>
> I have found another weird bug. It apprears to be a problem with the
> way the return statement handles Array refs and Hash refs in scalar
> context. I have some tests in t/op/sub_return_values.t which test the
> array ref problem.

I also found a precedence bug with return while I was adding some tests
according to apocalypse & synopsis 6 (tests attached, with some todo_is
tests for "is rw" prototypes and named args passing). I am looking at
the code, but since this is the first time I've ever used haskell, I
haven't figured out how to fix it.

The failing test is:

sub numcmp ($x, $y) { return $x <=> $y }
is(numcmp(2,7),-1,"numcmp 1");

it seems that numcmp returns $x instead of the value of the <=>
statement

code taken from the top of:
http://www.perl.com/pub/a/2003/04/09/synopsis.html?page=2

Joost.


subtests.patch

Joost Diepenmaat

unread,
Mar 8, 2005, 6:49:54 AM3/8/05
to perl6-c...@perl.org
On Tue, Mar 08, 2005 at 12:41:40PM +0100, Joost Diepenmaat wrote:

> +todo_is(eval(
> +'sub swap (*@_ is rw) { @_[0,1] = @_[1,0]; }
> +@in = qw(1 2);
> +swap(@in);
> +@in'),
> +"2 1","swap");

Meh. That's wrong.

it shoud be:

todo_is(eval(
'sub swap (*@_ is rw) { @_[0,1] = @_[1,0]; }
@in = qw(1 2);
swap(@in);
"@in[]"'),
"2 1","swap");

Fixed patch attached.

Joost.

subtests.patch
Reply all
Reply to author
Forward
0 new messages