Skip to content

Commit b76bc89

Browse files
committed
Merge pull request #15807 from JuliaLang/jb/generator_destructuring
fix a bug in lowering generator expressions with `(a,b) in itr`
2 parents db6aca2 + 1df4315 commit b76bc89

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,9 +1963,9 @@
19631963
(let* ((argname (if (and (length= vars 1) (symbol? (car vars)))
19641964
(car vars)
19651965
(gensy)))
1966-
(splat (if (eq? argname (car vars))
1967-
'()
1968-
`((= (tuple ,@vars) ,argname)))))
1966+
(splat (cond ((eq? argname (car vars)) '())
1967+
((length= vars 1) `((= ,(car vars) ,argname)))
1968+
(else `((= (tuple ,@vars) ,argname))))))
19691969
(expand-forms
19701970
`(call (top Generator) (-> ,argname (block ,@splat ,expr))
19711971
,(if (length= ranges 1)

test/functional.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,9 @@ end
239239
@test_throws DimensionMismatch Base.IteratorND(1:2, (2,3))
240240

241241
@test collect(Base.Generator(+, [1,2], [10,20])) == [11,22]
242+
243+
# generator with destructuring
244+
let d = Dict(:a=>1, :b=>2), a = Dict(3=>4, 5=>6)
245+
@test Dict( v=>(k,) for (k,v) in d) == Dict(2=>(:b,), 1=>(:a,))
246+
@test Dict( (x,b)=>(c,y) for (x,c) in d, (b,y) in a ) == Dict((:a,5)=>(1,6),(:b,5)=>(2,6),(:a,3)=>(1,4),(:b,3)=>(2,4))
247+
end

0 commit comments

Comments
 (0)