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

named arguments in sub signature not filled with values in surrounding where clause #5697

Open
p6rt opened this issue Sep 26, 2016 · 3 comments

Comments

@p6rt
Copy link

p6rt commented Sep 26, 2016

Migrated from rt.perl.org#129364 (status was 'open')

Searchable as RT129364$

@p6rt
Copy link
Author

p6rt commented Sep 26, 2016

From @gfldex

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

@p6rt
Copy link
Author

p6rt commented Sep 28, 2016

From @jnthn

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

@p6rt
Copy link
Author

p6rt commented Sep 28, 2016

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant