Skip to content

Commit 3903d24

Browse files
committed
[v6.d REVIEW] Move updated coercer spec to experimental appendix
Our PoV for this is super flimsy and incomplete. The spec might be on the overengineered side. May as well not take any risks with this and defer it to 6.e
1 parent feb2033 commit 3903d24

File tree

2 files changed

+214
-214
lines changed

2 files changed

+214
-214
lines changed

APPENDICES/A04-experimental/01-misc.t

Lines changed: 213 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use lib $?FILE.IO.parent(3).add: 'packages';
33
use Test;
44
use Test::Util;
55

6-
plan 1;
6+
plan 12;
77

88
# This appendix contains features that may already exist in some implementations but the exact
99
# behaviour is currently not fully decided on.
@@ -15,3 +15,215 @@ plan 1;
1515
lives-ok { rt107638(1) },
1616
'native types and where clauses do not cause spurious circularities';
1717
}
18+
19+
subtest ':D DefiniteHow target (core types)' => {
20+
#####
21+
# XXX 6.e REVIEW: some of these might be overly specific.
22+
# E.g. :U<->:D coersions might be over-engineering that we should never implement, as even
23+
# basic type checks of coersions are rather costly (we don't yet do them in Rakudo)
24+
#####
25+
plan 8;
26+
is-deeply -> Int:D(Cool) $x { $x }("42"), 42, 'type';
27+
is-deeply -> Int:D(Cool:D) $x { $x }("42"), 42, ':D smiley';
28+
is-deeply -> Int:D() $x { $x }("42"), 42, 'implied Any';
29+
#?rakudo skip ':D/:U coerces NYI'
30+
is-deeply -> Array:D(List:U) $x { $x }(List), [List,], ':U smiley';
31+
32+
is-deeply -> Int:D(Cool) $x { $x }("42"), 42, 'type';
33+
is-deeply -> Int:D(Cool:D) $x { $x }("42"), 42, ':D smiley';
34+
is-deeply -> Int:D() $x { $x }("42"), 42, 'implied Any';
35+
#?rakudo skip ':D/:U coerces NYI'
36+
is-deeply -> Array:D(List:U) $x { $x }(List), [List,], ':U smiley';
37+
}
38+
39+
subtest ':U DefiniteHow target (core types)' => {
40+
plan 3;
41+
is-deeply -> Date:U(DateTime) $x { $x }(DateTime), Date, 'type';
42+
is-deeply -> Date:U(DateTime:U) $x { $x }(DateTime), Date, ':U smiley';
43+
is-deeply -> Date:U() $x { $x }(DateTime), Date, 'implied Any';
44+
}
45+
46+
subtest 'DefiniteHow target, errors' => {
47+
#####
48+
# XXX 6.e REVIEW: some of these might be overly specific.
49+
# E.g. :U<->:D coersions might be over-engineering that we should never implement, as even
50+
# basic type checks of coersions are rather costly (we don't yet do them in Rakudo)
51+
#####
52+
plan 4;
53+
my \XPIC = X::Parameter::InvalidConcreteness;
54+
#?rakudo 4 todo 'no proper concreteness check in coerces'
55+
throws-like -> Date:D(DateTime) {}(DateTime), XPIC, 'type, bad source';
56+
throws-like -> Date:D(DateTime:D) {}(DateTime), XPIC, ':D, bad source';
57+
throws-like -> Date:D(DateTime:U) {}(DateTime), XPIC, ':U, bad target';
58+
throws-like -> Date:D() {}(DateTime), XPIC, 'implied, bad target';
59+
}
60+
61+
subtest 'DefiniteHow target, errors, source is already target' => {
62+
#####
63+
# XXX 6.e REVIEW: some of these might be overly specific.
64+
# E.g. :U<->:D coersions might be over-engineering that we should never implement, as even
65+
# basic type checks of coersions are rather costly (we don't yet do them in Rakudo)
66+
#####
67+
plan 4;
68+
my \XPIC = X::Parameter::InvalidConcreteness;
69+
#?rakudo 4 todo 'no proper concreteness check in coerces'
70+
throws-like -> Date:D(DateTime) {}(Date), XPIC, 'type';
71+
throws-like -> Date:D(DateTime:D) {}(Date), XPIC, ':D';
72+
throws-like -> Date:D(DateTime:U) {}(Date), XPIC, ':U';
73+
throws-like -> Date:D() {}(Date), XPIC, 'implied';
74+
}
75+
76+
{
77+
#####
78+
# XXX 6.e REVIEW: some of these might be overly specific.
79+
# E.g. :U<->:D coersions might be over-engineering that we should never implement, as even
80+
# basic type checks of coersions are rather costly (we don't yet do them in Rakudo)
81+
#####
82+
my class Target {...}
83+
my class Source { method Target { self.DEFINITE ?? Target.new !! Target } }
84+
my class SourceU { method Target { self.DEFINITE ?? Target !! Target.new } }
85+
my class Target is Source is SourceU {}
86+
my class SubSource is Source {}
87+
my class SubSourceU is SourceU {}
88+
89+
subtest ':D DefiniteHow target (arbitrary types; from source)' => {
90+
plan 6;
91+
is-deeply -> Target:D(Source) $x { $x }(Source.new), Target.new,
92+
'from type';
93+
is-deeply -> Target:D(Source:D) $x { $x }(Source.new), Target.new,
94+
'from :D smiley';
95+
#?rakudo skip ':D/:U coerces NYI'
96+
is-deeply -> Target:D(Source:U) $x { $x }(SourceU), Target.new,
97+
'from :U smiley';
98+
is-deeply -> Target:D(Any) $x { $x }(Source.new), Target.new,
99+
'from Any';
100+
is-deeply -> Target:D(Any:D) $x { $x }(Source.new), Target.new,
101+
'from Any:D';
102+
103+
# https://github.com/rakudo/rakudo/issues/1361
104+
is-deeply -> Target:D() $x { $x }(Source.new), Target.new,
105+
'from implied Any';
106+
}
107+
108+
subtest ':D DefiniteHow target (arbitrary types; from source subclass)' => {
109+
plan 6;
110+
is-deeply -> Target:D(Source) $x { $x }(SubSource.new), Target.new,
111+
'from type';
112+
is-deeply -> Target:D(Source:D) $x { $x }(SubSource.new), Target.new,
113+
'from :D smiley';
114+
#?rakudo skip ':D/:U coerces NYI'
115+
is-deeply -> Target:D(Source:U) $x { $x }(SubSourceU), Target.new,
116+
'from :U smiley';
117+
is-deeply -> Target:D(Any) $x { $x }(SubSource.new), Target.new,
118+
'from Any';
119+
is-deeply -> Target:D(Any:D) $x { $x }(SubSource.new), Target.new,
120+
'from Any:D';
121+
is-deeply -> Target:D() $x { $x }(SubSource.new), Target.new,
122+
'from implied Any';
123+
}
124+
125+
subtest ':D DefiniteHow target (arbitrary types; already target)' => {
126+
plan 6;
127+
is-deeply -> Target:D(Source) $x { $x }(Target.new), Target.new,
128+
'from type';
129+
is-deeply -> Target:D(Source:D) $x { $x }(Target.new), Target.new,
130+
'from :D smiley';
131+
#?rakudo skip ':D/:U coerces NYI'
132+
is-deeply -> Target:D(Source:U) $x { $x }(Target.new), Target.new,
133+
'from :U smiley';
134+
is-deeply -> Target:D(Any) $x { $x }(Target.new), Target.new,
135+
'from Any';
136+
is-deeply -> Target:D(Any:D) $x { $x }(Target.new), Target.new,
137+
'from Any:D';
138+
is-deeply -> Target:D() $x { $x }(Target.new), Target.new,
139+
'from implied Any';
140+
}
141+
142+
subtest ':U DefiniteHow target (arbitrary types; from source)' => {
143+
plan 6;
144+
is-deeply -> Target:U(Source) $x { $x }(Source), Target,
145+
'from type';
146+
#?rakudo skip ':D/:U coerces NYI'
147+
is-deeply -> Target:U(Source:D) $x { $x }(SourceU.new), Target,
148+
'from :D smiley';
149+
is-deeply -> Target:U(Source:U) $x { $x }(Source), Target,
150+
'from :U smiley';
151+
is-deeply -> Target:U(Any) $x { $x }(Source), Target,
152+
'from Any';
153+
is-deeply -> Target:U(Any:U) $x { $x }(Source), Target,
154+
'from Any:U';
155+
is-deeply -> Target:U() $x { $x }(Source), Target,
156+
'from implied Any';
157+
}
158+
159+
subtest ':U DefiniteHow target (arbitrary types; from source subclass)' => {
160+
plan 6;
161+
is-deeply -> Target:U(Source) $x { $x }(SubSource), Target,
162+
'from type';
163+
#?rakudo skip ':D/:U coerces NYI'
164+
is-deeply -> Target:U(Source:D) $x { $x }(SubSourceU.new), Target,
165+
'from :D smiley';
166+
is-deeply -> Target:U(Source:U) $x { $x }(SubSource), Target,
167+
'from :U smiley';
168+
is-deeply -> Target:U(Any) $x { $x }(SubSource), Target,
169+
'from Any';
170+
is-deeply -> Target:U(Any:U) $x { $x }(SubSource), Target,
171+
'from Any:U';
172+
is-deeply -> Target:U() $x { $x }(SubSource), Target,
173+
'from implied Any';
174+
}
175+
176+
subtest ':U DefiniteHow target (arbitrary types; already target)' => {
177+
plan 6;
178+
is-deeply -> Target:U(Source) $x { $x }(Target), Target,
179+
'from type';
180+
#?rakudo skip ':D/:U coerces NYI'
181+
is-deeply -> Target:U(Source:D) $x { $x }(Target), Target,
182+
'from :D smiley';
183+
is-deeply -> Target:U(Source:U) $x { $x }(Target), Target,
184+
'from :U smiley';
185+
is-deeply -> Target:U(Any) $x { $x }(Target), Target,
186+
'from Any';
187+
#?rakudo skip ':D/:U coerces NYI'
188+
is-deeply -> Target:U(Any:D) $x { $x }(Target), Target,
189+
'from Any:D';
190+
is-deeply -> Target:U() $x { $x }(Target), Target,
191+
'from implied Any';
192+
}
193+
}
194+
195+
subtest 'mistyped typenames in coercers give good error' => {
196+
plan 2;
197+
ok 1; ok 1;
198+
# sub test-it { throws-like $^code, X::Undeclared::Symbols, $code }
199+
# subtest 'in signature' => {
200+
# plan +my @tests = «
201+
# 「sub (Int(Coor)) {}」
202+
# 「sub (Innt(Cool)) {}」
203+
# 「sub (Innt(Coor)) {}」
204+
#
205+
# 「sub (Int(Coor:D)) {}」
206+
# 「sub (Int:D(Coor)) {}」
207+
# 「sub (Int:D(Coor:D)) {}」
208+
#
209+
# 「sub (Innt(Cool:D)) {}」
210+
# 「sub (Innt:D(Cool)) {}」
211+
# 「sub (Innt(Cool:D)) {}」
212+
#
213+
# 「sub (Innt(Coor:D)) {}」
214+
# 「sub (Innt:D(Coor)) {}」
215+
# 「sub (Innt:D(Coor:D)) {}」
216+
# »;
217+
# .&test-it for @tests;
218+
# }
219+
#
220+
# subtest 'standalone' => {
221+
# plan +my @tests = «
222+
# 「my $x = Int(Coor)」 「my $x = Innt(Cool)」 「my $x = Innt(Coor)」
223+
# 「my $x = Int(Coor:D)」 「my $x = Int:D(Coor)」 「my $x = Int:D(Coor:D)」
224+
# 「my $x = Innt(Cool:D)」 「my $x = Innt:D(Cool)」 「my $x = Innt(Cool:D)」
225+
# 「my $x = Innt(Coor:D)」 「my $x = Innt:D(Coor)」 「my $x = Innt:D(Coor:D)」
226+
# »;
227+
# .&test-it for @tests;
228+
# }
229+
}

0 commit comments

Comments
 (0)