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

[WIP] Enhance interop of generics, roles, and classes, Raku or nqp #808

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions S03-smartmatch/signature-signature.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 38;
plan 49;

#L<S03/Smart matching/Signature-signature>
{
Expand Down Expand Up @@ -35,14 +35,23 @@ plan 38;
:(*%), :(:$ ($, $)), True,
:(|), :(:$ ($, $)), True,
:(:$b ($, $)), :(:$a ($, $)), False,
:(Any ::T, T), :(Cool ::T, T), True,
:(Any ::T, T), :(Cool ::T, Mu), False,
:(::T, Cool), :(Cool ::T, T), True,
:(::T, T), :(::T, ::U), True,
:(::A, A ::AA, AA ::OW ::HOT, HOT ::AAAA), :(Mu, Any, Cool, Str), True,
:(Mu, Mu, Mu), :(::BI, BI ::DI, ::BABIDI), True,
:(--> Mu), :(--> Any), True,
:(), :(--> Mu), False,
:(Cool --> Cool), :(Str ::T --> T), True,
:(--> 1), :(--> 1), True,
:(--> 1), :(--> 0), False,
);

for @tests -> $s1, $s2, $res {
is(($s2 ~~ $s1), $res, "{$s2.raku} ~~ {$s1.raku}");
}

#?rakudo skip "Parametric types"
# Can't deal with parameters.
ok (:(::T $x, T $y) R~~ :(Str $y, Str $z)), "Parametric types";

ok (:(&foo:(Str --> Bool)) ~~ :(&bar:(Str --> Bool))),
Expand Down
3 changes: 0 additions & 3 deletions S09-typed-arrays/native-shape1-int.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ for flat @int,@uint -> $T {
diag "Testing $t array";

ok array[$T].new(:shape(5)) ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok array[$T].new(:shape(5)) ~~ Positional[$T], "$t array is Positional[$t]";
ok array[$T].new(:shape(5)).of === $T, "$t array .of is $t";

my @a := EVAL "my $t @[5]";
ok @a ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a ~~ Positional[$T], "$t array is Positional[$t]";
ok @a.of === $T, "$t array .of is $t";
ok @a.new ~~ Positional, ".new from $t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a.new ~~ Positional[$T], ".new from $t array Positional[$t]";
ok @a.new.of === $T, ".new from $t array .of is $t";

Expand Down
3 changes: 0 additions & 3 deletions S09-typed-arrays/native-shape1-num.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ for @num -> $T {
diag "Testing $t array";

ok array[$T].new(:shape(5)) ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok array[$T].new(:shape(5)) ~~ Positional[$T], "$t array is Positional[$t]";
ok array[$T].new(:shape(5)).of === $T, "$t array .of is $t";

my @a := EVAL "my $t @[5]";
ok @a ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a ~~ Positional[$T], "$t array is Positional[$t]";
ok @a.of === $T, "$t array .of is $t";
ok @a.new ~~ Positional, ".new from $t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a.new ~~ Positional[$T], ".new from $t array Positional[$t]";
ok @a.new.of === $T, ".new from $t array .of is $t";

Expand Down
3 changes: 0 additions & 3 deletions S09-typed-arrays/native-shape1-str.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ my $t = $T.^name;
diag "Testing $t array";

ok array[$T].new(:shape(5)) ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok array[$T].new(:shape(5)) ~~ Positional[$T], "$t array is Positional[$t]";
ok array[$T].new(:shape(5)).of === $T, "$t array .of is $t";

my @a := EVAL "my $t @[5]";
ok @a ~~ Positional, "$t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a ~~ Positional[$T], "$t array is Positional[$t]";
ok @a.of === $T, "$t array .of is $t";
ok @a.new ~~ Positional, ".new from $t array is Positional";
#?rakudo todo 'apparently it is not a typed Positional'
ok @a.new ~~ Positional[$T], ".new from $t array Positional[$t]";
ok @a.new.of === $T, ".new from $t array .of is $t";

Expand Down
12 changes: 6 additions & 6 deletions S12-introspection/parents.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ ok @parents[0].WHAT =:= B, 'first parent is B';
ok @parents[1].WHAT =:= C, 'second parent is C';

@parents = D.^parents(:tree);
is +@parents, 2, 'with :tree, D has two immediate parents (on proto)';
ok @parents[0] ~~ Array, ':tree gives back nested arrays for each parent (on proto)';
ok @parents[1] ~~ Array, ':tree gives back nested arrays for each parent (on proto)';
is +@parents, 2, 'with :tree, D has two immediate parents (on proto)';
ok @parents[0] ~~ List:D, ':tree gives back nested arrays for each parent (on proto)';
ok @parents[1] ~~ List:D, ':tree gives back nested arrays for each parent (on proto)';
sub walk(Mu $a) {
$a ~~ Positional
?? '(' ~ $a.map(&walk).join(', ') ~ ')'
Expand All @@ -95,9 +95,9 @@ is walk(@parents), walk( [[B, [A, [Any, [Mu]]]], [C, [A, [Any, [Mu]]]]]),
':tree gives back the expected data structure (on proto)';

@parents = D.new.^parents(:tree);
is +@parents, 2, 'with :tree, D has two immediate parents (on instance)';
ok @parents[0] ~~ Array, ':tree gives back nested arrays for each parent (on instance)';
ok @parents[1] ~~ Array, ':tree gives back nested arrays for each parent (on instance)';
is +@parents, 2, 'with :tree, D has two immediate parents (on instance)';
ok @parents[0] ~~ List:D, ':tree gives back nested arrays for each parent (on instance)';
ok @parents[1] ~~ List:D, ':tree gives back nested arrays for each parent (on instance)';
is walk(@parents), walk([[B, [A, [Any, [Mu]]]], [C, [A, [Any, [Mu]]]]]),
':tree gives back the expected data structure (on instance)';

Expand Down
46 changes: 33 additions & 13 deletions S14-roles/generic-subtyping.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@ use v6;

use Test;

plan 5;

lives-ok({ EVAL(Q:to/ROLES/) }, 'can do subtyped generic roles');
role R1[Any ::T] { }
role R2[Cool ::T] does R1[T] { }
ROLES

EVAL(Q:to/TESTS/);
ok(R2[Cool] ~~ R1[Any], 'subtyped generic roles');
ok(R2[Cool] ~~ R2[Cool], 'subtyped generic roles');
ok(R2[Int] ~~ R2[Cool], 'subtyped generic roles');
TESTS
role R2[Cool ::T] is R1[T] { }

role R3[Stringy ::T] does R2[T] { }

role R4[Str ::T] does R2[T] is R3[T] { }

only infix:<checks>(Mu $a is raw, Mu $b is raw) is test-assertion {
ok $a ~~ $b, "$a.raku() ~~ $b.raku()";
nok $b ~~ $a, "$b.raku() !~~ $a.raku()";
}

plan 2;

subtest 'subtyped generic roles can typecheck', {
plan 14 * 2;

lives-ok({ EVAL(Q:to/ROLE/) }, 'can lookup roles of subtyped generic roles done by roles before they get composed');
multi sub trait_mod:<is>(Mu:U \T, :ok($)!) { T.^roles[0].^roles }
R2[Str] checks R2;
R2[Str] checks R1;
R2[Str] checks R1[Any];
R2[Str] checks R2[Cool];
R3[Str] checks R1;
R3[Str] checks R1[Any];
R3[Str] checks R3[Stringy];
R4[Allomorph] checks R3;
R4[Allomorph] checks R2;
R4[Allomorph] checks R1;
R4[Allomorph] checks R1[Any];
R4[Allomorph] checks R2[Cool];
R4[Allomorph] checks R3[Stringy];
R4[Allomorph] checks R4[Str];
};

role R2[Int ::T] does R1[T] is ok { }
lives-ok({ EVAL Q:to/ROLE/ }, 'can lookup generic doees of a role before they get composed');
multi trait_mod:<is>(Mu:U \T, :roled($)!) { T.^roles[0].^roles }
role R5[Int ::T] does R2[T] is roled { }
ROLE

# vim: expandtab shiftwidth=4
1 change: 1 addition & 0 deletions spectest.data
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ S14-roles/parameter-subtyping.t
S14-roles/parameterized-basic.t
S14-roles/parameterized-mixin.t
S14-roles/parameterized-type.t
S14-roles/generic-subtyping.t
S14-roles/rw.t
S14-roles/stubs.t
S14-roles/submethods-6e.t
Expand Down