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

Wrong error report with Base.@kwdef #42820

Open
AIxer opened this issue Oct 27, 2021 · 1 comment
Open

Wrong error report with Base.@kwdef #42820

AIxer opened this issue Oct 27, 2021 · 1 comment
Labels
domain:error messages Better, more actionable error messages

Comments

@AIxer
Copy link

AIxer commented Oct 27, 2021

It seems like if you have an error in struct definition with Base.@kwdef, you can always get a error report which indicate that the error take place in util.jl, like:
the source code in TestKwdef.jl:

module TestKwdef

export Foo

Base.@kwdef mutable struct Foo
    a::Int = 1
    b::Int = c  # error!  line: 7 in my editor
end

end # module

but the error report:

julia> foo = Foo()
ERROR: UndefVarError: c not defined
Stacktrace:
 [1] Foo()
   @ TestKwdef .\util.jl:450
 [2] top-level scope
   @ REPL[4]:1

here's versioninfo:

julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, znver2)
Environment:
  JULIA_PKG_SERVER = https://mirrors.sjtug.sjtu.edu.cn/julia
@AIxer AIxer changed the title Wrong code error report in Base.kwdef Wrong error report with Base.@kwdef Oct 27, 2021
@johnnychen94 johnnychen94 added the domain:error messages Better, more actionable error messages label Oct 27, 2021
@Seelengrab
Copy link
Contributor

Seelengrab commented Oct 27, 2021

Can reproduce on

julia> versioninfo()
Julia Version 1.8.0-DEV.798
Commit 3ae25059fb (2021-10-22 06:13 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

From @macroexpand:

julia> @macroexpand Base.@kwdef mutable struct Foo2
           a::Int = 1
           b::Int = c
       end
quote
    #= util.jl:500 =#
    begin
        $(Expr(:meta, :doc))
        mutable struct Foo2
            #= REPL[5]:2 =#
            a::Int
            #= REPL[5]:3 =#
            b::Int
        end
    end
    #= util.jl:501 =#
    Foo2(; a = 1, b = c) = begin
            #= util.jl:478 =#
            Foo2(a, b)
        end
end

Seems like there are linenodes from the macro in there - should they be the same as inside the struct?

@AIxer AIxer closed this as completed Nov 9, 2021
@fredrikekre fredrikekre reopened this Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error messages Better, more actionable error messages
Projects
None yet
Development

No branches or pull requests

4 participants