Permalink
Browse files

Implement :D :U :T :_ (fixes #82)

  • Loading branch information...
1 parent 0d05837 commit 6fdfdad6bcdeb2bf6ff0a2bd6e182da0b8242f80 @sorear committed Dec 31, 2011
Showing with 36 additions and 12 deletions.
  1. +24 −0 lib/Kernel.cs
  2. +12 −12 test3.pl
View
@@ -1414,6 +1414,8 @@ public class Parameter : P6any, IFixup {
public const int TYPE_ONLY = 0x100000;
public const int DEF_MASK = 0x1C0000;
+ public const int DEF_SHIFT = 18;
+
// Value binding
public const int READWRITE = 2;
public const int RWTRANS = 8;
@@ -1771,6 +1773,22 @@ public class UsedInScopeInfo {
if (quiet) return null;
return Kernel.Die(th, "No value for parameter " + PName(param));
gotit:
+ switch ((flags & Parameter.DEF_MASK) >> Parameter.DEF_SHIFT) {
+ // TODO: Failure will make these cases different
+ case Parameter.TYPE_ONLY >> Parameter.DEF_SHIFT:
+ case Parameter.UNDEF_ONLY >> Parameter.DEF_SHIFT:
+ if (!src.Fetch().IsDefined())
+ break;
+ if (quiet) return null;
+ return Kernel.Die(th, "Parameter " + PName(param) + " requires an undefined argument");
+ case Parameter.DEF_ONLY >> Parameter.DEF_SHIFT:
+ if (src.Fetch().IsDefined())
+ break;
+ if (quiet) return null;
+ return Kernel.Die(th, "Parameter " + PName(param) + " requires a defined argument");
+ default:
+ break;
+ }
if ((flags & Parameter.RWTRANS) != 0) {
} else if ((flags & Parameter.IS_COPY) != 0) {
if ((flags & Parameter.IS_HASH) != 0)
@@ -4620,6 +4638,12 @@ internal class MMDCandidate : MultiCandidate {
p.constrained = false;
p.type = pa.type;
+ if ((flags & Parameter.DEF_MASK) != Parameter.ANY_DEF &&
+ (flags & Parameter.DEF_MASK) != 0) {
+ p.constrained = true;
+ extra_constraints = true;
+ }
+
// XXX The long name model does not represent the full
// diversity of Perl 6 parameters, instead restricting
// them to 'only positional' or '1 name'
View
@@ -57,25 +57,25 @@
}
{
- sub foo(Any:U $) { }
- sub bar(Any:D $) { }
- sub moo(Any:_ $) { }
- sub cow(Any:T $) { }
+ sub foo(Any:U $) { } #OK
+ sub bar(Any:D $) { } #OK
+ sub moo(Any:_ $) { } #OK
+ sub cow(Any:T $) { } #OK
multi qux(Any:U $) { "U" }
multi qux(Any:D $) { "D" }
- eval_lives_ok "foo(Int)", ":U allows type objects";
- eval_dies_ok "foo(5)", ":U denies concrete objects";
+ lives_ok { eval "foo(Int)" }, ":U allows type objects";
+ dies_ok { eval "foo(5)" }, ":U denies concrete objects";
- eval_lives_ok "bar(5)", ":D allows concrete objects";
- eval_dies_ok "bar(Int)", ":D denies type objects";
+ lives_ok { eval "bar(5)" }, ":D allows concrete objects";
+ dies_ok { eval "bar(Int)" }, ":D denies type objects";
- eval_lives_ok "moo(5)", ":_ allows concrete objects";
- eval_lives_ok "moo(Int)", ":_ allows type objects";
+ lives_ok { eval "moo(5)" }, ":_ allows concrete objects";
+ lives_ok { eval "moo(Int)" }, ":_ allows type objects";
- eval_lives_ok "cow(Int)", ":T allows type objects";
- eval_dies_ok "cow(5)", ":T denies concrete objects";
+ lives_ok { eval "cow(Int)" }, ":T allows type objects";
+ dies_ok { eval "cow(5)" }, ":T denies concrete objects";
is qux(Int), 'U', 'multi can discriminate on :U/:D (1)';
is qux(5), 'D', 'multi can discriminate on :U/:D (2)';

0 comments on commit 6fdfdad

Please sign in to comment.