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

Bug with methods of an inner function in different scopes #18674

Closed
simonster opened this issue Sep 26, 2016 · 1 comment
Closed

Bug with methods of an inner function in different scopes #18674

simonster opened this issue Sep 26, 2016 · 1 comment
Labels
regression Regression in behavior compared to a previous version

Comments

@simonster
Copy link
Member

simonster commented Sep 26, 2016

On 0.5/master, there seem to be conflicting assumptions somewhere regarding scope when different methods of inner functions have different scopes.

function outer()
    inner(x) = x
    let y = 1
        inner() = y
        inner
    end
end

julia> outer()
ERROR: UndefVarError: y not defined
 in outer() at ./REPL[1]:2

This doesn't seem to make much sense, since inner isn't even called. In fact, I get the error even if I wrap the let block in if false ... end.

On 0.4:

julia> outer()
inner (generic function with 2 methods)

and inner works as expected.

For fun, this works:

function outer()
    inner(x) = x
    let y = 1
        (::typeof(inner))() = y
        inner
    end
end

but it prints a warning about a rewritten method definition every time outer is called.

It may be that this code pattern is actually impossible to handle since #13412, but if that's the case, we could be more explicit about that.

@simonster simonster added the regression Regression in behavior compared to a previous version label Sep 26, 2016
@simonster simonster changed the title Scoping bug with inner functions Bug with methods of an inner function in different scopes Sep 26, 2016
@yuyichao
Copy link
Contributor

Dup of #15602

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

2 participants