Skip to content

Commit

Permalink
fix #29175, invalid lowered IR from repeating code for declared types (
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Sep 17, 2018
1 parent c0afddf commit 3255f28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2750,12 +2750,37 @@ f(x) = yt(x)
,(delete-duplicates (append (lam:sp lam) capt-sp)))
,body)))

;; renumber ssavalues assigned in an expr, allowing it to be repeated
(define (renumber-assigned-ssavalues e)
(let ((vals (expr-find-all (lambda (x) (and (assignment? x) (ssavalue? (cadr x))))
e
cadadr)))
(if (null? vals)
e
(let ((repl (table)))
(for-each (lambda (id) (put! repl id (make-ssavalue)))
vals)
(let do-replace ((x e))
(if (or (atom? x) (quoted? x))
x
(if (eq? (car x) 'ssavalue)
(or (get repl (cadr x) #f) x)
(cons (car x)
(map do-replace (cdr x))))))))))

(define (convert-for-type-decl rhs t)
(if (equal? t '(core Any))
rhs
`(call (core typeassert)
(call (top convert) ,t ,rhs)
,t)))
(let* ((temp (if (or (atom? t) (ssavalue? t) (quoted? t))
#f
(make-ssavalue)))
(ty (or temp t))
(ex `(call (core typeassert)
(call (top convert) ,ty ,rhs)
,ty)))
(if temp
`(block (= ,temp ,(renumber-assigned-ssavalues t)) ,ex)
ex))))

;; convert assignment to a closed variable to a setfield! call.
;; while we're at it, generate `convert` calls for variables with
Expand Down
9 changes: 9 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6714,3 +6714,12 @@ struct T29145{A,B}
end
end
@test_throws TypeError T29145()

# issue #29175
function f29175(tuple::T) where {T<:Tuple}
prefix::Tuple{T.parameters[1:end-1]...} = tuple[1:length(T.parameters)-1]
x = prefix
prefix = x # force another conversion to declared type
return prefix
end
@test f29175((1,2,3)) === (1,2)

0 comments on commit 3255f28

Please sign in to comment.