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

where-clauses in parametric role signatures produce internal error #1186

Closed
p6rt opened this issue Jul 31, 2009 · 6 comments
Closed

where-clauses in parametric role signatures produce internal error #1186

p6rt opened this issue Jul 31, 2009 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jul 31, 2009

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

Searchable as RT68074$

@p6rt
Copy link
Author

p6rt commented Jul 31, 2009

From @moritz

12​:16 <@​moritz_> rakudo​: role A[Int $x where { $x % 2 == 0 }] { method s {
  'even' } }; role A[Int $x where{ $x % 2 == 1 }] {
method s {
  'odd' } }; class X does A[5]; say X.new.s
12​:16 < p6eval> rakudo a53a1c​: OUTPUT«Potential internal error​: bindability
  check may have done more than just binding.␤Potential
internal
  error​: bindability check may have done more than just
  binding.␤Ambiguous dispatch to multi '_block50'. Ambiguous
  candidates had signatures​:␤​:(Int $x where all({ ...
}))␤​:(Int
12​:16 < p6eval> ..$x whe…

So the where-clauses didn't have the effect of disambiguating the
dispatch, as they should.

Cheers,
Moritz

--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/

@p6rt
Copy link
Author

p6rt commented Aug 1, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S14-roles/parameterized-type.t

commit f1fa89ed11f37183f0126ed779a828fe151303a4
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sat Aug 1 04​:30​:24 2009 +0000

  [t/spec] Tests for RT #​68074
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;27827 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S14-roles/parameterized-type.t b/t/spec/S14-roles/parameterized-type.t
index 1b3c4d2..5eeff7f 100644
--- a/t/spec/S14-roles/parameterized-type.t
+++ b/t/spec/S14-roles/parameterized-type.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 24;
+plan 28;
 
 =begin pod
 
@@ -56,6 +56,31 @@ dies_ok { C4.new.call_fail },      'roles being used as type constraints inside
 is R2[C3].new.call_test,     'ok', 'classes being used as type constraints inside roles work';
 dies_ok { R2[C3].new.call_fail },  'classes being used as type constraints inside roles work';
 
+#?rakudo skip 'RT #68074'
+{
+    role A[Int $x where { $x % 2 == 0 }] {
+        method s { 'even' }
+    }
+    role A[Int $x where { $x % 2 == 1 }] {
+        method s { 'odd' }
+    }
+
+    class RT68074odd does A[5] {}
+
+    my $a;
+    lives_ok { $a = RT68074odd.new.s },
+             'can call method of class from role with parametric signature using where (odd)'; # and a partridge in a pear tree!
+    is $a, 'odd',
+       'role disambiguation via parametric signature with where works (odd)';
+
+    class RT68074even does A[74] {}
+
+    lives_ok { $a = RT68074even.new.s },
+             'can call method of class from role with parametric signature using where (even)';
+    is $a, 'even',
+       'role disambiguation via parametric signature with where works (even)';
+}
+
 #?pugs emit =end SKIP
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Aug 1, 2009

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

@p6rt
Copy link
Author

p6rt commented Aug 2, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S14-roles/parameterized-basic.t

commit 776faf26ebc889ddc3b194b3e33ff8af136fc953
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sun Aug 2 17​:14​:03 2009 +0000

  [t/spec] Tests for RT 68074​: class composition time multi dispatch
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;27850 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S14-roles/parameterized-basic.t b/t/spec/S14-roles/parameterized-basic.t
index 97eb1cb..b49bb60 100644
--- a/t/spec/S14-roles/parameterized-basic.t
+++ b/t/spec/S14-roles/parameterized-basic.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 22;
+plan 32;
 
 =begin pod
 
@@ -103,6 +103,53 @@ is(TTP_2.new.x("OH HAI"), 'got a Str() it was OH HAI', 'type variable in scope a
 dies_ok({ TTP_1.new.x("OH HAI") },                   'type constraint with parameterized type enforced');
 dies_ok({ TTP_2.new.x(42) },                         'type constraint with parameterized type enforced');
 
+# test multi dispatch on parameterized roles
+# not really basic anymore, but I don't know where else to put these tests
+#?rakudo skip 'composition time multi dispatch with generics/where-blocks'
+{
+    role MD_block[Int $x where { $x % 2 == 0 }] {
+        method what { 'even' };
+    }
+    role MD_block[Int $x where { $x % 2 == 1 }] {
+        method what { 'odd' };
+    }
+
+    class CEven does MD_block[4] { };
+    class COdd  does MD_block[3] { };
+
+    is CEven.new.what, 'even',
+       'multi dispatch on parameterized role works with where-blocks (1)';
+    is COdd.new.what,  'odd',
+       'multi dispatch on parameterized role works with where-blocks (2)';
+    is CEven.what, 'even',
+       'same with class methods (1)';
+    is COdd.what,  'odd',
+       'same with class methods (2)';
+    eval_dies_ok 'class MD_not_Int does MD_block["foo"] { }',
+                 "Can't compose without matching role multi";
+
+    role MD_generics[::T $a, T $b] {
+        method what { 'same type' }
+    }
+    role MD_generics[$a, $b] {
+        method what { 'different type' }
+    }
+    class CSame does MD_generics[[], []] { }
+    class CDiff does MD_generics[4,  {}] { }
+
+    is CSame.new.what, 'same type',
+       'MD with generics at class composition time (1)';
+    is CDiff.new.what, 'different type',
+       'MD with generics at class composition time (2)';
+
+    is CSame.what, 'same type',
+       'MD with generics at class composition time (class method) (1)';
+    is CDiff.what, 'different type',
+       'MD with generics at class composition time (class method) (2)';
+    eval_dies_ok 'class WrongFu does MD_generics[3] { }',
+       'MD with generics at class composition times fails (wrong arity)';
+}
+
 #?pugs emit =end SKIP
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Apr 23, 2010

From @jnthn

On Fri Jul 31 03​:19​:31 2009, mlenz@​physik.uni-wuerzburg.de wrote​:

12​:16 <@​moritz_> rakudo​: role A[Int $x where { $x % 2 == 0 }] { method s {
'even' } }; role A[Int $x where{ $x % 2 == 1 }] {
method s {
'odd' } }; class X does A[5]; say X.new.s
12​:16 < p6eval> rakudo a53a1c​: OUTPUT«Potential internal error​:
bindability
check may have done more than just binding.␤Potential
internal
error​: bindability check may have done more than just
binding.␤Ambiguous dispatch to multi '_block50'. Ambiguous
candidates had signatures​:␤​:(Int $x where all({ ...
}))␤​:(Int
12​:16 < p6eval> ..$x whe…

So the where-clauses didn't have the effect of disambiguating the
dispatch, as they should.

Some tricky hacking later​:

role A[Int $x where { $x % 2 == 0 }] { method s { 'even' } }
role A[Int $x where { $x % 2 == 1 }] { method s { 'odd' } }
class X does A[5] { }
say X.new.s;
class Y does A[6] { }
say Y.new.s;

Outputs​:

odd
even

\o/

Tests turned on, resolving ticket.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 23, 2010

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

@p6rt p6rt closed this as completed Apr 23, 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant