-
Notifications
You must be signed in to change notification settings - Fork 25
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-positive unbound argument for struct constructors with unions #265
Comments
I think Aqua is complaining that You probably need to separate the struct Foo{T}
x::Union{Nothing,Vector{T}}
Foo(v::Vector{T}) where T = new{T}(v)
Foo{T}(v::Vector{T}) where T = new{T}(v)
Foo{T}(::Nothing) where {T} = new{T}(nothing)
end |
Hmmm, that's a little annoying that the default constructor that Julia gives you fails this check though. Too bad. |
Agreed - seems like it might be worth an exception in the Aqua ruleset |
Using the example from above, I can easily get a real error (see below), so I think that Aqua reports a genuine issue here. julia> struct Foo{T}
x::Union{Nothing,Vector{T}}
end
julia> Foo(nothing)
ERROR: UndefVarError: `T` not defined
Stacktrace:
[1] Foo(x::Nothing)
@ Main ./REPL[1]:2
[2] top-level scope
@ REPL[2]:1 |
Can something be done in Julia itself to improve this? |
Yes, the error is real but the question is whether it's worth reporting. This gives an |
but couldn't all needed constructors be created so that all cases work out of the box? |
This would be fixed, if julia wouldn't create inner constructors without explicit type parameters at all. In the example in #265 (comment), I see no way how julia could automatically resolve this. What a user want's can be wastly different based on the context. |
I am having (what I think is) a similar problem with an module MyPackage
struct MyStruct{N,T}
elements::NTuple{N,T}
end
end and here's the error: julia> Aqua.test_all(MyPackage)
Skipping Base.active_repl
Skipping Base.active_repl_backend
Test Summary: | Pass Total Time
Method ambiguity | 1 1 1.6s
Unbound type parameters detected:
[1] MyPackage.MyStruct(elements::Tuple{Vararg{T, N}}) where {N, T} @ MyPackage /tmp/MyPackage/src/MyPackage.jl:6
Unbound type parameters: Test Failed at /home/gdalle/.julia/packages/Aqua/tHrmY/src/unbound_args.jl:37
Expression: isempty(unbounds)
Evaluated: isempty(Method[MyPackage.MyStruct(elements::Tuple{Vararg{T, N}}) where {N, T} @ MyPackage /tmp/MyPackage/src/MyPackage.jl:6]) |
If I have a struct with a union type that contains the only instance of a parametric typevar in it, Aqua complains that my struct's constructor has an unbound typevar:
Results in:
The text was updated successfully, but these errors were encountered: