Skip to content

Commit

Permalink
fix #25678: return matters for generated functions
Browse files Browse the repository at this point in the history
Just explicitely check for `CodeInfo` objects when doing the
interpolation of the generated parts. I initially tried a more
complicated version of this, which avoided doing this check if there was
more than one generated part, but that's probably not necessary here.
  • Loading branch information
simeonschaub committed May 10, 2021
1 parent ccf7824 commit 4194c8c
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -285,7 +285,14 @@
(define (generated-part- x genpart)
(cond ((or (atom? x) (quoted? x) (function-def? x)) x)
((if-generated? x)
(if genpart `($ ,(caddr x)) (cadddr x)))
(if genpart
;; can't use an ssavalue here since (caddr x) could be a return statement
(let ((tmp (gensy)))
`($ (block (= ,tmp ,(caddr x))
(if (call (core isa) ,tmp (core CodeInfo))
(return ,tmp)
,tmp))))
(cadddr x)))
(else (cons (car x)
(map (lambda (e) (generated-part- e genpart)) (cdr x))))))

Expand Down
7 changes: 7 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2787,3 +2787,10 @@ macro m_nospecialize_unnamed_hygiene()
end

@test @m_nospecialize_unnamed_hygiene()(1) === Any

# issue 25678
@generated f25678(x::T) where {T} = code_lowered(sin, Tuple{x})[]
@test f25678(pi/6) === sin(pi/6)

@generated g25678(x) = return :x
@test g25678(7) === 7

0 comments on commit 4194c8c

Please sign in to comment.