Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #29175, invalid lowered IR from repeating code for declared types #29194

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)