On Mon Sep 26 15:42:15 2016, gfldex wrote:
> sub f( | ( :$a) where { dd $a } ) {}; f 42
> 
> # OUTPUT«Mu␤Constraint type check failed for parameter '<anon>'␤in sub f 
> at <tmp> line 1␤  in block <unit> at <tmp> line 1␤␤»
> 
> # it should either work or complain that $a is not declared in this scope

Making it work would imply that we move checking of constraints to after 
unpacking the sub-signature, which would be a change of behavior from today 
(and mean that you cannot use the where clause to guard the unpack). So that's 
not really an option; it's useful in both ways, and you can get the other way 
by simply moving the where clause inside of the sub-signature.

$ ./perl6-m -e 'sub f( | ( :$a where { dd $a } ) ) {}; f a => 42'
Int $a = 42
Constraint type check failed for parameter '$a' in sub-signature
  in sub f at -e line 1
  in block <unit> at -e line 1

The fail is simply because `dd` returns `Nil`, which is falsey.

The problem with "not declared" is that it is declared in that the symbol has 
already been poked into the symbol table, it's just not yet bound to a value 
because the where clause runs prior to the unpack. Contrast it with:

$ ./perl6-m -e 'sub f( | where { dd $a } (:$a) ) {}; f 42'
===SORRY!=== Error while compiling -e
Variable '$a' is not declared
at -e:1
------> sub f( | where { dd ⏏$a } (:$a) ) {}; f 42

Which fails as expected.

In summary, I'm not at all sure we want to "make it work". Some kind of warning 
or error that you reference the symbol before it's bound is possible, though I 
suspect implementing it will involve quite some contortions, as it goes against 
the one-passing that such errors typically fall out of.

/jnthn

Reply via email to