From 6e5b031082b23995914d58f570daaabc321a943a Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sun, 27 Mar 2022 02:05:55 -0400 Subject: [PATCH] fix oc lowering with return type annotations (#44727) fixes #44723 Co-authored-by: Takafumi Arakaki (cherry picked from commit 19eb3073561266f5e1699e9f4f9d52c65b42d76f) --- src/julia-syntax.scm | 20 ++++++++++++-------- test/syntax.jl | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index d1f681479bc55..852af7c704b17 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -4018,7 +4018,7 @@ f(x) = yt(x) (cons (car e) (map-cl-convert (cdr e) fname lam namemap defined toplevel interp opaq)))))))) -(define (closure-convert e) (cl-convert e #f #f #f #f #f #f #f)) +(define (closure-convert e) (cl-convert e #f #f (table) (table) #f #f #f)) ;; pass 5: convert to linear IR @@ -4118,17 +4118,21 @@ f(x) = yt(x) (loop (cdr s)))))) `(pop_exception ,restore-token)))) (define (emit-return x) - (define (actually-return x) - (let* ((x (if rett - (compile (convert-for-type-decl x rett) '() #t #f) - x)) - (tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x) + (define (emit- x) + (let* ((tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x) #f (make-ssavalue)))) - (if tmp (emit `(= ,tmp ,x))) + (if tmp + (begin (emit `(= ,tmp ,x)) tmp) + x))) + (define (actually-return x) + (let* ((x (if rett + (compile (convert-for-type-decl (emit- x) rett) '() #t #f) + x)) + (x (emit- x))) (let ((pexc (pop-exc-expr catch-token-stack '()))) (if pexc (emit pexc))) - (emit `(return ,(or tmp x))))) + (emit `(return ,x)))) (if x (if (> handler-level 0) (let ((tmp (cond ((and (simple-atom? x) (or (not (ssavalue? x)) (not finally-handler))) #f) diff --git a/test/syntax.jl b/test/syntax.jl index c769bcc0730ab..be2f7e05af68f 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -3046,3 +3046,7 @@ end let ex = :(const $(esc(:x)) = 1; (::typeof(2))() = $(esc(:x))) @test macroexpand(Main, Expr(:var"hygienic-scope", ex, Main)).args[3].args[1] == :((::$(GlobalRef(Main, :typeof))(2))()) end + +# issue 44723 +demo44723()::Any = Base.Experimental.@opaque () -> true ? 1 : 2 +@test demo44723()() == 1