Skip Menu |
Report information
Id: 129364
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: gfldex <wenzel.peppmeyer [at] gmx.de>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: "Wenzel P. P. Peppmeyer" <wenzel.peppmeyer [...] gmx.de>
Subject: named arguments in sub signature not filled with values in surrounding where clause
Date: Tue, 27 Sep 2016 00:41:54 +0200 (CEST)
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 257b
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
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.6k
On Mon Sep 26 15:42:15 2016, gfldex wrote: Show quoted text
> 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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org