-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Unions with static type parameters are problematic #3738
Comments
|
Should this be documented somewhere as a gotcha, for 0.2? (I ran in to it trying to use None as a default argument) |
I've just ran into this. This would be very useful since in many cases keyword arguments need to have a "no-op" default, specified by |
As Jeff alludes to, this isn't unique to keyword arguments. I've updated the title to make it a bit more obvious for future searchers. The following modification to the above keyword case is a nice reduced example: julia> type Foo{T} x::T end
julia> g{T}(x::Foo{T}, y::Union(Symbol, T)) = println(y)
g (generic function with 1 method)
julia> g(Foo(1), :bar)
ERROR: MethodError: `g` has no method matching g(::Foo{Int64}, ::Symbol)
Closest candidates are:
g{T}(::Foo{T}, ::Union(Symbol,T))
julia> g(Foo(1), 1)
1
julia> g(Foo(:baz), :qux)
qux It didn't occur to me that the parameter within the union would also try to match, as opposed to simply binding to the result of the match in the other (non-Union) arguments. It seems like that'd be a decent simplification to the NP-complete problem and yet work in almost all of the useful cases, no? |
@JeffBezanson Does the partial solution suggested by @mbauman sound reasonable to you? |
That doesn't quite work since a common use for type-parameter matching within unions is An alternate idea I played with a few weeks ago is disallowing Unions whose components are non-orthoganol in method signatures… but I didn't manage to see it the whole way through. |
All of these examples are fixed on master. |
Do we know what fixed them? Are there corresponding tests? |
Stdlib: Pkg URL: https://github.com/JuliaLang/Pkg.jl.git Stdlib branch: master Julia branch: master Old commit: 85f1e5564 New commit: 3c86ba27e Julia version: 1.11.0-DEV Pkg version: 1.11.0 Bump invoked by: @IanButterworth Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/Pkg.jl@85f1e55...3c86ba2 ``` $ git log --oneline 85f1e5564..3c86ba27e 3c86ba27e add `add --weak/extra Foo` to add to [weakdeps] or [extras] (#3708) 2e640f92f respect --color=no in Pkg.precompile (#3740) cbd5d08ad Automatically add compat entries when adding deps to a package (#3732) 03de920b3 rm old manual handling of `--compiled-modules` (#3738) 314d5497b Use realpaths for temp dirs during tests. Fix SparseArrays `why` breakage (#3734) a6531d4be environments.md: update Julia version (#3715) a509bc062 Revise the API of is_manifest_current. (#3701) 60b7b7995 rm incorrect kwargs in add docstring (#3733) ``` Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
This works:
A parametric version instead fails with a cryptic message:
Possibly related, this should be an error but less cryptic and preferrably when the function is defined rather than used.
The text was updated successfully, but these errors were encountered: