From 36169a922c64916884608b7cb3032a174efeab75 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Wed, 17 Feb 2021 21:33:33 +0100 Subject: [PATCH] fix #39705: lowering of Expr(:||) (#39709) (cherry picked from commit 0858864409596d158d2ab7f5bc49308c1f718bdc) --- src/julia-syntax.scm | 5 ++++- test/cartesian.jl | 4 ++++ test/syntax.jl | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 4debe7324598e..48b175680c535 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1927,7 +1927,10 @@ (stmts (if blk? (cdr (butlast test)) '())) (test (if blk? (last test) test))) (if (and (pair? test) (memq (car test) '(&& |\|\||))) - (let ((clauses `(,(car test) ,@(map expand-forms (cdr (flatten-ex (car test) test)))))) + (let* ((clauses `(,(car test) ,@(map expand-forms (cdr (flatten-ex (car test) test))))) + (clauses (if (null? (cdr clauses)) + (if (eq? (car clauses) '&&) '(true) '(false)) + clauses))) `(if ,(if blk? `(block ,@(map expand-forms stmts) ,clauses) clauses) diff --git a/test/cartesian.jl b/test/cartesian.jl index 32c3e1fb0a4e6..af0bc466e3d04 100644 --- a/test/cartesian.jl +++ b/test/cartesian.jl @@ -405,3 +405,7 @@ end @test @inferred(intersect(I, J)) == CartesianIndices((2:3, 4:5)) end + +# issue #39705 +f39705() = Base.Cartesian.@nany 0 _ -> true +@test f39705() === false diff --git a/test/syntax.jl b/test/syntax.jl index 68f32b600b79d..b032283523c4f 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2700,3 +2700,7 @@ end @test eval(Expr(:string, "a", Expr(:string, "b", "c"))) == "abc" @test eval(Expr(:string, "a", Expr(:string, "b", Expr(:string, "c")))) == "abc" + +# issue #39705 +@eval f39705(x) = $(Expr(:||)) && x +@test f39705(1) === false