Skip to content

Commit

Permalink
make .= return its right hand side. fixes #25954
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 16, 2018
1 parent 7d170be commit 95b57e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,12 @@

'.=
(lambda (e)
(expand-fuse-broadcast (cadr e) (caddr e)))
`(ifvalue
,(let ((temp (make-ssavalue)))
`(block ,(expand-forms `(= ,temp ,(caddr e)))
,(expand-fuse-broadcast (cadr e) temp)
,temp))
,(expand-fuse-broadcast (cadr e) (caddr e))))

'|<:|
(lambda (e) (expand-forms `(call |<:| ,@(cdr e))))
Expand Down Expand Up @@ -3679,6 +3684,8 @@ f(x) = yt(x)
(if value
(compile (cadr e) break-labels value tail)
#f))
((ifvalue)
(compile (if value (cadr e) (caddr e)) break-labels value tail))
((if elseif)
(let ((test `(gotoifnot ,(compile-cond (cadr e) break-labels) _))
(end-jump `(goto _))
Expand Down
12 changes: 12 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,15 @@ let n = 1
@test ceil.(Int, n ./ (1,)) == (1,)
@test ceil.(Int, 1 ./ (1,)) == (1,)
end

# issue #25954, value of `.=`
let a = zeros(2, 3), b = zeros(4, 5)
a .= b .= 1
@test a == ones(2, 3)
@test b == ones(4, 5)
@test (b .= 1) === 1
c = [6, 7]; d = [8, 9]
x = (a .= c.+d)
@test a == [14 14 14; 16 16 16]
@test x == [14, 16]
end

0 comments on commit 95b57e9

Please sign in to comment.