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 handling for local variable used as an inner function parameter #26814

Open
iwelch opened this issue Apr 15, 2018 · 2 comments
Open

error handling for local variable used as an inner function parameter #26814

iwelch opened this issue Apr 15, 2018 · 2 comments
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) domain:error handling Handling of exceptions by Julia or the user

Comments

@iwelch
Copy link

iwelch commented Apr 15, 2018

mutable struct Point; x::Float64; end#struct 

function x()
    Point(x::Int) = Point( Float64(x) )
    isindomain( p::Point )= (!isinf(p.x))

    println(isindomain(Point(2)) && "we are all good")
end

I am going to guess that initializers are not allowed to be local. however, I am neither certain that this is the problem, nor is this a big problem. it can be easily cured by moving the initializer out of the function.

if I am correct, and one should not create function-local initializers, then may I suggest a better error message that says precisely this? the obscure error is just not informative enough, and this can probably be easily detected.

if I am incorrect, oh well, then I am just, as often, confused.

@JeffBezanson
Copy link
Sponsor Member

Right; in this example Point is a function-valued local variable of function x. So inside the function, Point only refers to that local variable and no longer refers to the global type name. I agree the error message can be improved though.

@JeffBezanson JeffBezanson added domain:error handling Handling of exceptions by Julia or the user compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels Apr 15, 2018
@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 1, 2024

At some point this was fixed (v1.0)

ERROR: syntax: local variable Point cannot be used in closure declaration

and then quickly regressed again:

ERROR: UndefVarError: `#5#Point` not defined in `Main`
Suggestion: check for spelling errors or missing imports.

but better than it was originally

ERROR: type DataType has no field contents

@vtjnash vtjnash changed the title baffling error error handling for local variable used as an inner function parameter Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

No branches or pull requests

3 participants