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



Reply via email to