nsajko
January 22, 2023, 3:10pm
1
julia> struct S{T} end
julia> T(::S{T}) where {T <: Any} = one(T)
T (generic function with 0 methods)
It seems Julia is confused by the function name being the same as a type parameter. I guess Julia should throw an error here instead of defining a function without the method?
EDIT: Issue on Github:
opened 10:04PM - 11 Oct 19 UTC
bug
good first issue
I encountered the following behavior, which is just odd:
```
julia> T(a, b, c)… where T = 1
T (generic function with 0 methods)
```
Apparently what happened was:
1. It created a method `T`
2. It added the defined method to something else (`TypeVar`, `Any` - one of them anyway)
3. It returned the method `T`
According to @JeffBezanson this should do "something else, whatever it may be", so here's the issue for that.
2 Likes
Yes, it’s weird that a function was defined but no method was added nor was there an error. It’s beyond my depth to understand what happened here.
In case you haven’t found it yet, you were probably looking for this
julia> (::Type{T})(::S{T}) where T = one(T)
julia> Float64(S{Float64}())
1.0
2 Likes