Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit return of Failure Broken in routines with native return type constraints #5727

Open
p6rt opened this issue Oct 5, 2016 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 5, 2016

Migrated from rt.perl.org#129811 (status was 'new')

Searchable as RT129811$

@p6rt
Copy link
Author

p6rt commented Oct 5, 2016

From @zoffixznet

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-archive.perl.org/perl6/Ticket/Display.html?id=129373#ticket-history

@p6rt
Copy link
Author

p6rt commented Jan 3, 2018

From @zoffixznet

Related Issue​: rakudo/rakudo#1360

@p6rt
Copy link
Author

p6rt commented Feb 26, 2018

From @zoffixznet

Related issue​: rakudo/rakudo#1571

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant