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

literals and boxed types do not get unboxed for native types in multies #5741

Closed
p6rt opened this issue Oct 10, 2016 · 3 comments
Closed

literals and boxed types do not get unboxed for native types in multies #5741

p6rt opened this issue Oct 10, 2016 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 10, 2016

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

Searchable as RT129844$

@p6rt
Copy link
Author

p6rt commented Oct 10, 2016

From zoffix@zoffix.com

We can use a literal numeral or an Int with a sub that takes a native​:

<Zoffix> m​: sub foo (int) { say "OK!" }; foo 2
<camelia> rakudo-moar d03459​: OUTPUT«OK!␤»
<Zoffix> m​: sub foo (int) { say "OK!" }; my Int $x = 2; foo $x
<camelia> rakudo-moar d03459​: OUTPUT«OK!␤»

But, such auto-unboxing doesn't work if we use a multi instead​:

<Zoffix> m​: multi foo (int) { say "OK!" }; foo 2
<camelia> rakudo-moar d03459​: OUTPUT«Cannot resolve caller foo(Int);
none of these signatures match​:␤ (int)␤ in block <unit> at <tmp>
line 1␤␤»
<Zoffix> m​: multi foo (int) { say "OK!" }; my Int $x = 2; foo $x
<camelia> rakudo-moar d03459​: OUTPUT«Cannot resolve caller foo(Int);
none of these signatures match​:␤ (int)␤ in block <unit> at <tmp>
line 1␤␤»

Even though auto-boxing for natives works regardless of whether we
have a multi​:

<Zoffix> m​: sub foo (Int) { say "OK!" }; my int $x = 2; foo $x
<camelia> rakudo-moar d03459​: OUTPUT«OK!␤»
<Zoffix> m​: multi foo (Int) { say "OK!" }; my int $x = 2; foo $x
<camelia> rakudo-moar d03459​: OUTPUT«OK!␤»

I found this bug while out on a hunt for another one, and it looks
like the solutions might be very similar, so I'm filing this with a
tentative "leave it with me."

As part of this issue and the one I'm resolving, I had to write out a
list of rules of how literals, natives, and their related types behave
in multi resolution​:

  (I describe int/Int, but same applies for other natives that have
a boxed Perl 6 equivalent)​:

  0) Literal​: treat as Int
  1) Int​:
  1.1) Use as Int, if have candidate
  1.2) Use as native, if​:
  1.2.1) have native candidate
  1.2.2) size fits
  2) Native​:
  2.1) Use as native, if have candidate
  2.2) Use as Int, if have candidate
  And so we have​:

  my int $i = 2; # used in all examples to indicate native int

  multi foo (int $x) {say "native" };
  foo 2; # native; 0 => 1 => 1.2

  multi foo (Int $x) {say "other Int" };
  foo 2; # other Int; 0 => 1 => 1.1

  multi foo (int $x) {say "native" };
  foo $i; # native; 2 => 2.1

  multi foo (Int $x) {say "other Int" };
  foo $i; # other Int; 2 => 2.2

  multi foo (int $x) {say "native" };
  multi foo (Int $x) {say "other Int" };
  foo 2; # other Int; 0 => 1 => 1.1
  foo $i; # native; 2 => 2.1

  multi foo (int $x) {say "native" };
  multi foo (Str $x) {say "other Str" };
  foo 2; # native; 0 => 1 => 1.2
  foo $i; # native; 2 => 2.1

  multi foo (Int $x) {say "other Int" };
  multi foo (Str $x) {say "other Str" };
  foo 2; # other Int; 0 => 1 => 1.1
  foo $i; # other Int; 2 => 2.2

  multi foo (int $x) {say "native" };
  multi foo (Int $x) {say "other Int" };
  foo 2; # other Int; 0 => 1 => 1.1
  foo 2**100; # other Int; 0 => 1 => 1.1

  multi foo (int $x) {say "native" };
  foo 2; # native; 0 => 1.2
  foo 2**100; # X​::Multi​::NoMatch (no Int candidate);
  # 0 => 1 => 1.2 => 1.2.2 (fails to match at this point)

  multi foo (int $x, int $y) {say "native" };
  multi foo (Int $x, Int $y) {say "other Int" };
  foo 2, $i; # other Int; (0 => 1 => 1.1), (2 => 2.1)
  foo 2, 2; # other Int; (0 => 1 => 1.1), (0 => 1 => 1.1)
  foo $i, $i; # native; (2 => 2.1), (2 => 2.1)

  multi foo (int $x, int $y) {say "native" };
  multi foo (Int $x, int $y) {say "Int + native" };
  multi foo (Int $x, Int $y) {say "other Int" };
  foo 2, $i; # Int + native; (0 => 1 => 1.1), (2 => 2.1)
  foo 2, 2; # other Int; (0 => 1 => 1.1), (0 => 1 => 1.1)
  foo $i, $i; # native; (2 => 2.1), (2 => 2.1)

@p6rt
Copy link
Author

p6rt commented Oct 25, 2016

From @zoffixznet

Per jnthn's comments this is not a bug​: https://irclog.perlgeek.de/perl6-dev/2016-10-25#i_13462673

Will close after https://rt-archive.perl.org/perl6//Public/Bug/Display.html?id=128655 is sorted

@p6rt p6rt added the Bug label Jan 5, 2020
@usev6
Copy link

usev6 commented Feb 19, 2023

The link to the IRC logs doesn't work anymore. I think it would be this discussion (with some context further up): https://colabti.org/irclogger/irclogger_log/perl6-dev?date=2016-10-25#l164

Will close after https://rt-archive.perl.org/perl6//Public/Bug/Display.html?id=128655 is sorted

Since that issue (which lives at #5460 now) is closed, I'll go ahead and close this one as well (as "Won't fix"). Please reopen, if you disagree.

@usev6 usev6 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2023
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

2 participants