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

multimethod calls with subsets as type constraints fail when called the second time #5086

Closed
p6rt opened this issue Jan 25, 2016 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 25, 2016

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

Searchable as RT127367$

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

From rightfold@gmail.com

Consider the following code​:

use v6.c;

subset T of List where *[0] eqv 1;

class R {
  multi method f(T​:D $xs) { self.f(42) }
  multi method f(Any​:D $xs) { say $xs }
}

R.f([1, 2]);
R.f([2, 2]);

It fails with the following output​:

42
Type check failed in binding $xs; expected T but got Array
  in method f at /tmp/foo.pm6 line 6
  in block <unit> at /tmp/foo.pm6 line 11

However, when the R.f([1, 2]) call is removed, the program succeeds.

Thanks to masak++ for helping minimizing the example.

Rakudo version​:

This is Rakudo version 2015.12 built on MoarVM version 2015.12 implementing Perl 6.c.

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

From @masak

<ely-se> the interesting thing is that Any​:D is a catchall
<masak> ely-se​: if I remove the first (successful) call to .f, the second one starts working!
<masak> ely-se​: feels like a screwing-up of method caches...
<ely-se> eek caches
<masak> aye
<masak> ely-se​: inlining T as a `where` in the siggie also makes things work properly
<masak> ely-se​: (so one way to work around it would be to inline the subtype)
<masak> ely-se​: as far as I can see, it fails because we first match T correctly, but in the second invocation we match List but not T.
<ely-se> yay I inlined the constraints and now my tests pass :)
<masak> m​: subset T of List where { .[0] == 1 }; .f([1, 2]) && .f([2, 2]) given class C { multi method f(T​:D $) { self.f(42) }; multi method f($xs) { say $xs } }
<camelia> rakudo-moar d67cb0​: OUTPUT«42␤Type check failed in binding <anon>; expected T but got Array␤ in method f [...]
<masak> getting golfier by the minute
<masak> m​: subset N of Int where * == 5; .f(5), .f(7) given class C { multi method f(N​:D $) { self.f("OH HAI") }; multi method f($x) { say $x } }
<camelia> rakudo-moar d67cb0​: OUTPUT«OH HAI␤Type check failed in binding <anon>; expected N but got Int␤ in method f [...]
<masak> ely-se​: it's not just Lists

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

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

@p6rt
Copy link
Author

p6rt commented Feb 7, 2016

From @LLFourn

I just hit this. Another way of getting the example code working is to
remove the '​:D'.

use v6.c;

subset T of List where *[0] eqv 1;

class R {
  multi method f(T $xs) { self.f(42) }
  multi method f(Any​:D $xs) { say $xs }
}

R.f([1, 2]);
R.f([2, 2]);

# ^^ works fine
So something to do with Definite types and caching i'd say.

@p6rt
Copy link
Author

p6rt commented Aug 2, 2016

From @zoffixznet

Thanks for the report.

This has been fixed in rakudo/rakudo@68afa3ff
Tests added in Raku/roast@b00a4f4a5c

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Aug 2, 2016

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

@p6rt p6rt closed this as completed Aug 2, 2016
@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