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 when trying to assign a function name to a constant variable is confusing #9773

Closed
dhoegh opened this issue Jan 14, 2015 · 5 comments
Closed
Labels
domain:error handling Handling of exceptions by Julia or the user

Comments

@dhoegh
Copy link
Contributor

dhoegh commented Jan 14, 2015

When you get the error

julia>const ff = 1
julia>ff()=1
invalid method definition: not a generic function

When I saw this in a large code block I was very puzzled about what julia tried to tell my. While when the variable name is not a constant then the error seems much more understandable:

julia>f = 1
julia>f()=1
cannot define function f; it already has a value

Where it is clear what julia means.

@nalimilan
Copy link
Member

Indeed. Though I'd rather say cannot define function f: an object with this name already exists.

@aviks aviks changed the title error when trying to assing a function name to a constant variable is confusing error when trying to assign a function name to a constant variable is confusing Jan 14, 2015
@JeffBezanson
Copy link
Sponsor Member

This is in jl_method_def in toplevel.c. It's easy to add the variable name to this error message.

@dhoegh
Copy link
Contributor Author

dhoegh commented Jan 14, 2015

My main concern where the wording of the error. not a generic function do not say anything about what the user done wrong while it already has a value does.

@simonster simonster added the domain:error handling Handling of exceptions by Julia or the user label Jan 14, 2015
@dhoegh
Copy link
Contributor Author

dhoegh commented Feb 4, 2015

Thank you. @JuliaBackports

JeffBezanson added a commit that referenced this issue Feb 6, 2015
@tkelman
Copy link
Contributor

tkelman commented Feb 6, 2015

backported in 5b25589

dhoegh pushed a commit to dhoegh/julia that referenced this issue Feb 12, 2015
ihnorton added a commit that referenced this issue May 6, 2015
It's croaking [here](https://github.com/JuliaLang/julia/blob/79599ada444fcc63cb08aed64b4ff6a415bb4d29/src/interpreter.c#L260).
We backported 97381df (fix for #9773) which gives the nice error message,
but didn't remove the related assert, which was removed in 2604610.
@ihnorton ihnorton mentioned this issue May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

No branches or pull requests

5 participants