JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
266 stars 32 forks source link

improve error message for `new` missing type parameters. #431

Open oscardssmith opened 1 month ago

oscardssmith commented 1 month ago

Currently the following code

struct A{T}
    t::T
    function A(t)
        new(t)
    end
end

produces the syntax error

ERROR: syntax: too few type parameters specified in "new{...}" around REPL[3]:1
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

This isn't a bad error message; it correctly identifies new missing type parameters, but it's missing the nice JuliaSyntax highlighting, and doesn't say how many parameters were expected (not needed in this example, but for types with lots of params, it would be useful).

MasonProtter commented 1 month ago

I'm pretty sure this error is emitted from lowering, not from parsing so that's why it's so much less informative. Hopefully once lowering is in the julia side this can be fixed.