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

Return type mismatch should return Failure, not throw exception #2880

Open
p6rt opened this issue Aug 31, 2012 · 3 comments
Open

Return type mismatch should return Failure, not throw exception #2880

p6rt opened this issue Aug 31, 2012 · 3 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Aug 31, 2012

Migrated from rt.perl.org#114684 (status was 'open')

Searchable as RT114684$

@p6rt
Copy link
Author

p6rt commented Aug 31, 2012

From @pmichaud

  19​:34 <pmichaud> r​: sub abc() returns Int { my $r = 3.5; $r }; my $x = abc(); say 'alive';
  19​:34 <p6eval> rakudo 231137​: OUTPUT«Type check failed for return value; expected 'Int' but got 'Rat'␤ in sub abc at /tmp/P8uacuh4gB​:1␤ in block at /tmp/P8uacuh4gB​:1␤␤»

According to S02​:1363, a return value not matching a constraint should
internally call C<fail>, which means the above shouldn't die immediately.

jnthn++ notes that this may be a deviation from the way type constraints
are handled by other parts of the spec; thus the spec may want changing.
If so, we can file a spec issue for that; in the meantime I'm filing the
rakudobug so it doesn't get forgotten.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

On Fri, 31 Aug 2012 12​:36​:48 -0700, pmichaud wrote​:

19​:34 <pmichaud> r​: sub abc() returns Int { my $r = 3.5; $r }; my
$x = abc(); say 'alive';
19​:34 <p6eval> rakudo 231137​: OUTPUT«Type check failed for return
value; expected 'Int' but got 'Rat'␤ in sub abc at /tmp/P8uacuh4gB​:1␤
in block at /tmp/P8uacuh4gB​:1␤␤»

Still the same in current Rakudo​:

  This is Rakudo version 2017.08-104-g76f1d8970
  built on MoarVM version 2017.08.1-148-g1059eed1
  implementing Perl 6.c.

Better test-case​:

  ➜ sub abc() returns Int { 3.5 }; say abc.defined;
  Type check failed for return value; expected Int but got Rat (3.5)

Since there has been no update on this, and no-one's complaining about the current behavior, does this mean the ticket should be rejected?

(Marking it RFC for now.)

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

The RT System itself - Status changed from 'new' to 'open'

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

No branches or pull requests

1 participant