-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
The manual doesn't provide a definition for what it means to define a constructor for a parametric type where the number of type parameters accepted by the constructor is fewer than the number of type parameters for the type. In simple cases, it works as expected, but for more complicated cases, the lack of a formal semantics leads to mass confusion, as demonstrated by this Discourse thread.
From that thread, we came up with the following MWE.
This works:
julia> struct Bar{T, S} end
julia> Bar{T}() where {T} = T
julia> Bar{Integer}()
IntegerBut this does not:
julia> struct Foo{T, S <: T} end
julia> Foo{T}() where {T} = T
julia> Foo{Integer}()
ERROR: UndefVarError: T not defined
Stacktrace:
[1] Foo{Integer,S} where S<:Integer() at ./REPL[2]:1
[2] top-level scope at REPL[3]:1Without a definition of what it means to define Foo{T}() where {T} = # ... it's difficult to know if this is a bug or if this is expected behavior. And if it is the expected behavior, it would be nice to know what the semantic rule is that explains this behavior (and it would be nice to have that explanation in the manual).