Skip to content

Seemingly a bug with type variables having Tuple as a lower bound #39277

Closed
@julbinb

Description

@julbinb

(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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentationtypes and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions