-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationtypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
(Julia 1.5.3 and 1.0.5)
When a type variable has a Tuple lower bound, scoping of the type variable and allowed uses seem wrong.
Allowed usage
julia> foo(a::T) where {T>:Tuple} = (a,)
foo (generic function with 1 method)
julia> foo(1) # seems wrong
(1,)
julia> foo((1,))
((1,),)Scoping
julia> bar(a::T) where {T>:Tuple} = (a, T)
bar (generic function with 1 method)
julia> bar(1) # seems wrong
ERROR: UndefVarError: T not defined
Stacktrace:
[1] bar(::Int64) at ./REPL[1]:1
[2] top-level scope at none:0
julia> bar((1,))
ERROR: UndefVarError: T not defined
Stacktrace:
[1] bar(::Tuple{Int64}) at ./REPL[1]:1
[2] top-level scope at none:0
julia> baz(a::T) where {T>:Tuple{Int}} = (a, T)
baz (generic function with 1 method)
julia> baz(1)
ERROR: UndefVarError: T not defined
Stacktrace:
[1] baz(::Int64) at ./REPL[4]:1
[2] top-level scope at none:0
julia> baz((1,))
((1,), Tuple{Int64})Correct scoping:
julia> moo(a::T) where T = (a,T)
moo (generic function with 1 method)
julia> moo(5)
(5, Int64)
julia> moo((5,))
((5,), Tuple{Int64})(Examples were made in cooperation with @BenChung)
schneiderfelipe
Metadata
Metadata
Assignees
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationtypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch