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

Subclassing an Int no longer works flawlessly (my Foo $a .= new(42)) #5928

Closed
p6rt opened this issue Dec 29, 2016 · 6 comments
Closed

Subclassing an Int no longer works flawlessly (my Foo $a .= new(42)) #5928

p6rt opened this issue Dec 29, 2016 · 6 comments
Labels
regression Issue did not exist previously

Comments

@p6rt
Copy link

p6rt commented Dec 29, 2016

Migrated from rt.perl.org#130431 (status was 'resolved')

Searchable as RT130431$

@p6rt
Copy link
Author

p6rt commented Dec 29, 2016

From @AlexDaniel

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 rakudo/rakudo@798c2e2

<Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow. At least half of rakudo/rakudo@798c2e2 is wrong, because that comment lies; it doesn't give a "decoupled" Int

@p6rt
Copy link
Author

p6rt commented Dec 29, 2016

From @zoffixznet

On Wed, 28 Dec 2016 18​:58​:00 -0800, alex.jakimenko@​gmail.com wrote​:

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
rakudo/rakudo@798c2e2

<Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow.
At least half of
rakudo/rakudo@798c2e2
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 :/

@p6rt
Copy link
Author

p6rt commented Dec 29, 2016

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

@p6rt
Copy link
Author

p6rt commented Dec 30, 2016

From @AlexDaniel

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​:

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
rakudo/rakudo@798c2e2

<Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow.
At least half of
rakudo/rakudo@798c2e2
is wrong, because that comment lies; it doesn't give a "decoupled" Int

@p6rt
Copy link
Author

p6rt commented Feb 9, 2018

From @zoffixznet

On Thu, 29 Dec 2016 19​:26​:07 -0800, alex.jakimenko@​gmail.com wrote​:

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​:

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

rakudo/rakudo@798c2e2

<Zoffix> AlexDaniel, please rakudobug it. I'll take a look tomorrow.
At least half of

rakudo/rakudo@798c2e2

is wrong, because that comment lies; it doesn't give a "decoupled"
Int

This was already fixed awhile back and I'm 100% sure there are tests covering the issue as well (this was around when nqp​::fromI_I was being introed to fix constant caching here)

@p6rt
Copy link
Author

p6rt commented Feb 9, 2018

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Feb 9, 2018
@p6rt p6rt added the regression Issue did not exist previously label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Issue did not exist previously
Projects
None yet
Development

No branches or pull requests

1 participant