Skip to content

Commit dbd3d4c

Browse files
authored
fix #37413, propagating && conditions with elseif (#37453)
1 parent c0224d5 commit dbd3d4c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/julia-syntax.scm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,11 +1902,17 @@
19021902
(error (string "invalid " syntax-str " \"" (deparse el) "\""))))))))
19031903

19041904
(define (expand-if e)
1905-
(if (and (pair? (cadr e)) (eq? (car (cadr e)) '&&))
1906-
(let ((clauses (cdr (flatten-ex '&& (cadr e)))))
1907-
`(if (&& ,@(map expand-forms clauses))
1908-
,@(map expand-forms (cddr e))))
1909-
(cons (car e) (map expand-forms (cdr e)))))
1905+
(let* ((test (cadr e))
1906+
(blk? (and (pair? test) (eq? (car test) 'block)))
1907+
(stmts (if blk? (cdr (butlast test)) '()))
1908+
(test (if blk? (last test) test)))
1909+
(if (and (pair? test) (eq? (car test) '&&))
1910+
(let ((clauses `(&& ,@(map expand-forms (cdr (flatten-ex '&& test))))))
1911+
`(if ,(if blk?
1912+
`(block ,@(map expand-forms stmts) ,clauses)
1913+
clauses)
1914+
,@(map expand-forms (cddr e))))
1915+
(cons (car e) (map expand-forms (cdr e))))))
19101916

19111917
;; move an assignment into the last statement of a block to keep more statements at top level
19121918
(define (sink-assignment lhs rhs)

test/compiler/inference.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,8 @@ function symcmp36230(vec)
26912691
a, b = vec[1], vec[2]
26922692
if isa(a, Symbol) && isa(b, Symbol)
26932693
return a == b
2694+
elseif isa(a, Int) && isa(b, Int)
2695+
return a == b
26942696
end
26952697
return false
26962698
end

0 commit comments

Comments
 (0)