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

Strange interaction between return and try/finally #1784

Closed
toivoh opened this issue Dec 18, 2012 · 6 comments
Closed

Strange interaction between return and try/finally #1784

toivoh opened this issue Dec 18, 2012 · 6 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@toivoh
Copy link
Contributor

toivoh commented Dec 18, 2012

Discovered through toivoh/Debug.jl#30 :
It seems that try/finally doesn't like that you leave the try block using return.
Sometimes it gives a syntax error, as in

julia> let
           try
               return 5
           finally
               println("exiting")
           end                   
       end

syntax error: misplaced return statement at line 3

Sometimes, it just bypasses the finally block, as in

julia> let
           try
               return 5
               3
           finally
               println("exiting")
           end                   
       end

5

To my mind, both of these examples should print out "exiting", and then return the value 5.

The reason that I bring this up is because Debug.jl wraps each scope block in a try/finally to make sure to capture when you leave a block, e.g. for step over/out. If the fix is nontrivial, is there some way to work around this issue in the meantime?

@JeffBezanson
Copy link
Member

Yes, finally is not complete yet. This is on my secret todo list, and now it is on my public todo list :)

@ghost ghost assigned JeffBezanson Dec 18, 2012
@toivoh
Copy link
Contributor Author

toivoh commented Dec 19, 2012

Ok, good.

@stevengj
Copy link
Member

stevengj commented Aug 5, 2015

This does not seem fixed yet:

function foo()
    (a,b) = try
        return true
        (0,1)
    finally
        println("exiting")
    end
end

gives LoadError: syntax: misplaced return statement in master.

@yuyichao
Copy link
Contributor

Seems fixed now?

julia> function foo()
           (a,b) = try
               return true
               (0,1)
           finally
               println("exiting")
           end
       end
foo (generic function with 1 method)

julia> foo()
exiting
true

@tkelman
Copy link
Contributor

tkelman commented Feb 22, 2016

add a test?

@JeffBezanson
Copy link
Member

Possible this was fixed by my front-end redesign.

vtjnash added a commit that referenced this issue Mar 14, 2016
vtjnash added a commit that referenced this issue Mar 18, 2016
@yuyichao yuyichao added the needs tests Unit tests are required for this change label Mar 21, 2016
@tkelman tkelman removed the needs tests Unit tests are required for this change label Mar 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants