| |
perl.perl6.compiler |
Autrijus and Co. I have found another weird bug. It apprears to be a problem with the The following code: While all of the following code: I also suspect that the same bug is causing this code: because all of these (note the lack of return statement): will print out: Then there is this code: which won't even compile. The error is spits out is: Fail: cannot cast into [VPair]: VSub (Sub {isMulti = False, subName = I suspect this to might be a symptom of the above bug, but I cannot Anyway, Hope this helps out some. - Steve
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.
pugs -e 'sub foo { return [ 1, 2, 3 ] }; my $test = foo(); say
$test; say ref($test);'
will print out:
3
Int
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
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); return \%h;
two2
Pair
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);'
one 1
three 3
two 2
Hash
pugs -e 'sub foo { my %h = ("one",1,"two",2,"three",3); return %h; };
my %test = foo(); say %test; say ref(%test);'
"&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))]})
tell for sure.