Skip to content

Better line info for "missing comma or ) in argument list" error #16163

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

Closed
KristofferC opened this issue May 2, 2016 · 13 comments
Closed

Better line info for "missing comma or ) in argument list" error #16163

KristofferC opened this issue May 2, 2016 · 13 comments
Labels
error handling Handling of exceptions by Julia or the user parser Language parsing and surface syntax

Comments

@KristofferC
Copy link
Member

KristofferC commented May 2, 2016

Putting this in a file and include it:

function filler()
end

function g(a,b,c)
    f(a,b)
    f(a,b)
    f(a,(b,))
    f(a,(b,))
    f(a,(b,))
    f(a,(b,) # :(
    f(a,(b,))
    f(a,(b,))
    f(a,(b,))
end

gives the error message:

julia> include("test.jl")
ERROR: LoadError: syntax: missing comma or ) in argument list
 in include(::ASCIIString) at ./boot.jl:233
 in include_from_node1(::ASCIIString) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:236
while loading /home/kristoffer/Documents/test.jl, in expression starting on line 4

Is there anyway the line info could be a bit more specific than just the line of the start of the enclosing function?

@KristofferC KristofferC changed the title Better line info for missing comma Better line info for "missing comma or ) in argument list" error May 2, 2016
@yuyichao
Copy link
Contributor

yuyichao commented May 2, 2016

Dup of #15643

@yuyichao yuyichao closed this as completed May 2, 2016
@KristofferC
Copy link
Member Author

KristofferC commented May 2, 2016

That one has the title "bad stack trace for errors in macros". This example has no macros. Should the title in #15643 be updated?

@JeffBezanson
Copy link
Member

Looks like a different issue to me. This one is about syntax error locations.

@JeffBezanson JeffBezanson reopened this May 2, 2016
@JeffBezanson JeffBezanson added parser Language parsing and surface syntax error handling Handling of exceptions by Julia or the user labels May 2, 2016
@Keno
Copy link
Member

Keno commented May 2, 2016

Or you could just use JuliaParser ;):
screen shot 2016-05-02 at 12 39 25 pm

@KristofferC
Copy link
Member Author

KristofferC commented May 2, 2016

Wow, that is some clang level beauty right there.

@Keno
Copy link
Member

Keno commented May 2, 2016

@KristofferC
Copy link
Member Author

KristofferC commented May 9, 2016

Here is another example from a typo I made:

# test.jl
module Test

function filler()
    blabla
end

typealias a = Float64

end # module
julia> include("/home/kristoffer/Documents/test.jl")
ERROR: LoadError: syntax: unexpected "="
 in include_from_node1(::String) at ./loading.jl:426
 in eval(::Module, ::Any) at ./boot.jl:230
while loading /home/kristoffer/Documents/test.jl, in expression starting on line 1

@KristofferC
Copy link
Member Author

KristofferC commented Jul 24, 2016

Another one:

module M

function f()
    while true
        if x == 0 && y == 0
            a = 1
        if x == 1 && z == 1
            a = 2
        end
    end
end

end

This gives ERROR: syntax: incomplete: "module" at REPL[44]:1 requires end. For a large modules this is a quite unhelpful error and I usually end up pasting the whole module in the REPL and see where the latest completely parsed expression got completed. Maybe the Error message could show this as well?

@StefanKarpinski
Copy link
Member

I think the best way to give better error messages is probably to consider indentation. To me that suggests bailing out on a parse when there's an error and reparsing the input with a parser that is slower and tracks extra information like indentation and gives really high quality messages.

@vtjnash
Copy link
Member

vtjnash commented Aug 10, 2017

Would be awesome if we could have https://github.com/KristofferC/OhMyREPL.jl replace the default on_done / parse_input_line function with one that uses that fancier parser (https://github.com/ZacLN/CSTParser.jl) hint hint hint :) :) :)

@Keno
Copy link
Member

Keno commented Aug 10, 2017

Already in progress: https://github.com/Keno/FancyDiagnostics.jl

@felixcremer
Copy link
Contributor

felixcremer commented Feb 24, 2021

This is closed in julia 1.5. The first example gives:

julia> include("test.jl")
ERROR: LoadError: syntax: missing comma or ) in argument list
Stacktrace:
 [1] top-level scope at /home/user/Documents/Programmieren/julia_projects/tmp/test.jl:11
 [2] include(::String) at ./client.jl:457
 [3] top-level scope at REPL[1]:1
in expression starting at /home/user/Documents/Programmieren/julia_projects/tmp/test.jl:11

This is the line directly after the missing comma.

@laborg
Copy link
Contributor

laborg commented Oct 19, 2023

JuliaSyntax handles the first problem:

julia> include("bug.jl")
ERROR: LoadError: ParseError:
# Error @ /home/gerhard/bug.jl:11:5
    f(a,(b,) # :(
    f(a,(b,))
#   └─────┘ ── Expected `)`
Stacktrace:
 [1] top-level scope
   @ ~/bug.jl:11
 [2] include(fname::String)
   @ Base.MainInclude ./client.jl:496
 [3] top-level scope
   @ REPL[10]:1
in expression starting at /home/gerhard/bug.jl:11

The missing end message is still not optimal. Not sure if there is actually a way to improve this.

@vtjnash vtjnash closed this as completed Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

8 participants