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

Error: "my" variable %args masks earlier declaration in same scope #47

Open
barefootcoder opened this issue Mar 29, 2012 · 1 comment
Open
Labels

Comments

@barefootcoder
Copy link
Contributor

I've got a gist which demonstrates the error.

I'm not sure why I can't reproduce this error with Method::Signatures alone; it seems like it ought to have the same problem, but it doesn't. Only when I'm using Method::Signatures::Modifiers with MooseX::Declare. This leads me to believe that I'm doing something bad (or not doing something good) in MSM, so I'm hesitant to just jump in and "fix" the problem by changing MS's %args to %__METHOD_SIGNATURES_ARGS_WHICH_YOU_SHOULD_NOT_USE or something like that. Seems a bit like cheating anyway.

@schwern: Thoughts?

@schwern
Copy link
Contributor

schwern commented Aug 16, 2012

Cheating is ok. If we're going to leak lexicals, let's leak ones that are unlikely to cause a clash.

The better fix is to wrap our internal lexicals in a block so they don't leak out. Essentially do this:

# method glitch(:$foo)
my $self = shift;    # invocant
my $foo;               # all variables declared in the signature

# Do any work in a block to hide our temporary lexicals
{
    my %args = @_[0..$#_];
    $foo = delete $args{foo};
    Method::Signatures->named_param_error(\%args) if %args;
    Method::Signatures->too_many_args_error(1) if @_ > 2;
}

Keeping it all on the same line.

@schwern schwern added the Bug label Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants