Julia: more specific location for syntax errors

Created on 15 Mar 2014  Â·  7Comments  Â·  Source: JuliaLang/julia

test.jl:

function test(a, b)
  c = 0
  d = 3
  d = d + a(b, d]
end

julia test.jl:

ERROR: syntax: unexpected "]" in argument list in include_from_node1 at loading.jl:120 while loading test.jl, in expression starting on line 1

It would be better if the error will be point out more precisely (instead of just pointing at the beginning of the function).

error handling

Most helpful comment

I'm re-opening this. Duplicates of this issue keep appearing because Julia's syntax errors are often inordinately vague at the moment; we aren't anywhere close to the point of diminishing returns yet. We need an issue as a place to both centralize complaints and to track work that is being done to improve matters.

All 7 comments

Unless this is accompanied by a pull request to improve the parser, I'm going to close this as busywork that will most likely fall on @JeffBezanson. An unbounded amount of time and effort can be put into making the parser handle syntax errors better, but it's a matter of diminishing returns. That's not to say that improvements aren't welcomed – we will happily merge pull requests that improve error messages!

I'm re-opening this. Duplicates of this issue keep appearing because Julia's syntax errors are often inordinately vague at the moment; we aren't anywhere close to the point of diminishing returns yet. We need an issue as a place to both centralize complaints and to track work that is being done to improve matters.

4744 ?

@tkelman, that issue is for generic improvements to error messages; this one is specific to line numbers.

Ooh! This is going to be really nice! I added a NEWS.md item.

Re-opening this issue due to @dfagnan's example in #8828, which reports an error on "line 1" no matter where in the for loop you put the problematic expression (even dozens of lines later).

for i=1:10
    if false |           # Should error on line 2.
        continue
    end
end

I just ran into this. I'm definitely not the most experienced Julian, but we have to be able to do better than

ERROR: syntax: missing comma or ) in argument list
Stacktrace:
 [1] top-level scope at none:1

for

function foo()
           x=1
           bar(a b)
end

If you're typing it in line by line, the experience is fine since the error comes right after you hit the offending line, but if you're copy-pasting code in, not having any indication what line was the problem is really annoying.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sbromberger picture sbromberger  Â·  3Comments

i-apellaniz picture i-apellaniz  Â·  3Comments

iamed2 picture iamed2  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments

yurivish picture yurivish  Â·  3Comments