Skip to content

Destructed arguments cannot be properly used to define optional arguments #53832

@frankwswang

Description

@frankwswang

MWE:

julia> f1(a::Tuple{T, T}, c::T=a[1]) where {T} = (a[1], c, a[2])
f1 (generic function with 2 methods)

julia> f2((a, b)::Tuple{T, T}, c::T=a) where {T} = (a, c, b)
f2 (generic function with 2 methods)

julia> f1((1, 2))
(1, 1, 2)

julia> f2((1, 2))
ERROR: UndefVarError: `a` not defined

System environment by versioninfo():

Julia Version 1.10.2
Commit bd47eca2c8 (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 20 × 12th Gen Intel(R) Core(TM) i9-12900HK
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 20 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions