Skip Menu |
Report information
Id: 129811
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cpan [at] zoffix.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Implicit return of Failure Broken in routines with native return type constraints
To: rakudobug [...] perl.org
From: cpan [...] zoffix.com
Date: Wed, 05 Oct 2016 17:14:44 -0400
Download (untitled) / with headers
text/plain 2.4k
If we let the Failure to be implicitly returned from a sub or method with a native return type constraint, it appears to attempt to unbox the Failure object into the type, failing at it. The Failure is not subject to type constraint and must be passed unhindered: <Zoffix> m: sub (--> int) { Failure.new }() <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native integer: P6opaque, Failure␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» <Zoffix> m: sub (--> num) { Failure.new }() <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native number: P6opaque, Failure␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» <Zoffix> m: sub (--> str) { Failure.new }() <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native string: P6opaque, Failure␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» <Zoffix> m: class { method foo (--> str) { Failure.new } }.foo <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native string: P6opaque, Failure␤ in method foo at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» Of note is that the bug does NOT happen if we *explicitly* return the Failure: <Zoffix> m: sub (--> int) { return Failure.new }() <camelia> rakudo-moar 62d838: OUTPUT«Failed␤ in block <unit> at <tmp> line 1␤␤Actually thrown at:␤ in block <unit> at <tmp> line 1␤␤» <Zoffix> m: sub (--> int) { fail }() <camelia> rakudo-moar 62d838: OUTPUT«Failed␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤Actually thrown at:␤ in block <unit> at <tmp> line 1␤␤» Or use a block instead of a sub: <Zoffix> m: ->--> int { Failure.new }() <camelia> rakudo-moar 62d838: OUTPUT«Failed␤ in block <unit> at <tmp> line 1␤␤Actually thrown at:␤ in block <unit> at <tmp> line 1␤␤» Currently, this bug affects core power operator on native types when overflow is meant to be thrown: <Zoffix> m: say (my int $ = 2**30) ** (my int $ = 2**30) <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native integer: P6opaque, Failure␤ in block <unit> at <tmp> line 1␤␤» <Zoffix> m: say (my num $ = 2**30) ** (my num $ = 2**30) <camelia> rakudo-moar 62d838: OUTPUT«This type cannot unbox to a native number: P6opaque, Int␤ in block <unit> at <tmp> line 1␤␤» RT#129373 may or may not be related: https://rt.perl.org/Ticket/Display.html?id=129373#ticket-history


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org