# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #129811]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129811 >



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

Reply via email to