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

Breaking behavior with nested function definitions #18071

Closed
davidanthoff opened this issue Aug 16, 2016 · 1 comment
Closed

Breaking behavior with nested function definitions #18071

davidanthoff opened this issue Aug 16, 2016 · 1 comment

Comments

@davidanthoff
Copy link
Contributor

This used to work on julia 0.4:

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.0-rc2+0 (2016-08-12 11:25 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-w64-mingw32

julia> function f(x)
         if x
           bar()=5
         else
           bar()=1
         end
         return bar
       end
WARNING: Method definition bar() in module Main at REPL[1]:3 overwritten at REPL[1]:5.
f (generic function with 1 method)

julia> f(true)
(::bar) (generic function with 1 method)

julia> f(false)
ERROR: UndefVarError: bar not defined
 in f(::Bool) at .\REPL[1]:7

julia>

There are two things that I find strange: why is there a warning when I compile f? And why doesn't the second invocation work?

I am aware that one can use anonymous functions instead.

It is not clear to me whether this is a bug, or by design. If by design, it would be good to mention this in the NEWS section. Also, if by design, is there still a point to allow these nested function definitions at all?

@andreasnoack
Copy link
Member

I hit this one yesterday. It's #15602

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

2 participants