Skip Menu |
Report information
Id: 130431
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: alex.jakimenko [at] gmail.com
Cc:
AdminCc:

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



Subject: [REGRESSION] Subclassing an Int no longer works flawlessly (my Foo $a .= new(42))
Download (untitled) / with headers
text/plain 645b
Code: class Mebibytes is Int { method Str { (self/1024/1024).Int ~ "M" } }; my Mebibytes $a .= new(183456783); $a.say; # fancy enough? Result (2016.09): 174M Result (HEAD): Type check failed in assignment to $a; expected Mebibytes but got Int (183456783) in block <unit> at /tmp/4Vz0jddWQp line 1 Bisectable points to https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854 <Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow. At least half of https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854 is wrong, because that comment lies; it doesn't give a "decoupled" Int
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Wed, 28 Dec 2016 18:58:00 -0800, alex.jakimenko@gmail.com wrote: Show quoted text
> Code: > class Mebibytes is Int { method Str { (self/1024/1024).Int ~ "M" } }; > my Mebibytes $a .= new(183456783); $a.say; # fancy enough? > > > Result (2016.09): > 174M > > > Result (HEAD): > Type check failed in assignment to $a; expected Mebibytes but got Int > (183456783) > in block <unit> at /tmp/4Vz0jddWQp line 1 > > > Bisectable points to > https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854 > > > <Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow. > At least half of > https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854 > is wrong, because that comment lies; it doesn't give a "decoupled" Int
Looking deeper into it, the comment doesn't lie, it does seem to work to decouple from cached constants: # HEAD <Zoffix> m: my $y = Int.new: 2; my $x = 2; 2 does role Foo {}; dd $y <camelia> rakudo-moar 19df35: OUTPUT«Int $y = 2␤» # 2012.15 <Zoffix> committable6, 2015.12 my $y = Int.new: 2; my $x = 2; 2 does role Foo {}; dd $y <committable6> Zoffix, ¦«2015.12»: Int+{Foo} $y = 2 Can't figure out how to get the cake and eat it too, though... I can either make it create a new self.WHAT maintaining subclassing object OR handle huge values like 2⁶⁴ correctly. Other than doing something stupid, like coercing it to Str and then using nqp::fromstr_I :/
Another case:

class MyInt is Int { method even(){ self %% 2 } }; say [1..4].map({ MyInt.new($_) }).grep({.even})


Seems like it is a common thing to try, but I'm not going to say that it should work. Maybe it should throw a warning or something? If the warning can give clear instructions on how to do this kind of stuff, then I'd say we provided enough cakes.

On 2016-12-28 18:58:00, alex.jakimenko@gmail.com wrote:
Show quoted text
> Code:
> class Mebibytes is Int { method Str { (self/1024/1024).Int ~ "M" } };
> my Mebibytes $a .= new(183456783); $a.say; # fancy enough?
>
>
> Result (2016.09):
> 174M
>
>
> Result (HEAD):
> Type check failed in assignment to $a; expected Mebibytes but got Int
> (183456783)
> in block <unit> at /tmp/4Vz0jddWQp line 1
>
>
> Bisectable points to
> https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854
>
>
> <Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow.
> At least half of
> https://github.com/rakudo/rakudo/commit/798c2e2dca34e5cf93da99d1f401eb161efca854
> is wrong, because that comment lies; it doesn't give a "decoupled" Int




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