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

false positives with Base.@kwdef #487

Closed
dpinol opened this issue Mar 30, 2023 · 2 comments · Fixed by #532
Closed

false positives with Base.@kwdef #487

dpinol opened this issue Mar 30, 2023 · 2 comments · Fixed by #532

Comments

@dpinol
Copy link
Contributor

dpinol commented Mar 30, 2023

Not sure if I should split into 2 issues:

1) plain Base.@kwdef

Create a package with

Base.@kwdef struct KWS
    myField::Int
end

report_package reports this error

═════ 2 possible errors found ═════
┌ @ util.jl:493 throw(UndefKeywordError(:myField))
│ UndefKeywordError: keyword argument myField not assigned: throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────
┌ @ util.jl:493  = throw(UndefKeywordError(:a))
│ UndefKeywordError: keyword argument myField not assigned:  = throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────

2) Base.@kwdef with non used parameter

Create a package with

Base.@kwdef struct KWS{T}
    myField::Int
end

report_package reports more errors

═════ 6 possible errors found ═════
┌ @ util.jl:504 SCEngine.KWS(myField)
│ no matching method found `SCEngine.KWS(::Any)`: SCEngine.KWS(myField::Any)
└───────────────
┌ @ util.jl:504 throw(UndefKeywordError(:myField))
│ UndefKeywordError: keyword argument myField not assigned: throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────
┌ @ util.jl:504  = throw(UndefKeywordError(:myField))
│ UndefKeywordError: keyword argument myField not assigned:  = throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────
┌ @ util.jl:504 Base.kwerr(_2, _3)
│┌ @ error.jl:163 Base.kwerr(::Any, ::Type{SCEngine.KWS})
││ may throw: Base.throw(Base.MethodError((((Base.typeof((args::Tuple{Type})[1]::Type{SCEngine.KWS})::DataType).name::Core.TypeName).mt::Core.MethodTable).kwsorter::Any, tuple(tuple(kw::Any)::Tuple{Any}, args::Tuple{Type}...)::Tuple{Any, Type})::MethodError)
│└────────────────
┌ @ util.jl:505 throw(UndefKeywordError(:myField))
│ UndefKeywordError: keyword argument myField not assigned: throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────
┌ @ util.jl:505  = throw(UndefKeywordError(:myField))
│ UndefKeywordError: keyword argument myField not assigned:  = throw(UndefKeywordError(:myField)::UndefKeywordError)
└───────────────

thanks!

@jakobnissen
Copy link
Contributor

Reduced example:

struct Bar
    x
end
Bar(; x) = Bar(x)

It appears to be because the constructor Bar() contant-evaluates to throwing the error. It's a little tricky to debug because keyword arguments are "magic" and intentionally hide a bunch of their inner workings.

aviatesk added a commit that referenced this issue Jun 4, 2023
In most cases `UncaughtErrorReport` or `SeriousExceptionReport` are
the noise when detected in top-level definition analysis, since some
methods are intentionally written to throw errors.

- fixes #477
- fixes #487
@dpinol
Copy link
Contributor Author

dpinol commented Feb 27, 2024

Second issue reported at #615 (now it only generates 1 error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants