From b992fe6e239e99f0bfb41d399994a268fc937479 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 16 Jan 2016 16:59:35 -0500 Subject: [PATCH] fix #14691, wrong value returned from `a.b = c` expression --- src/julia-syntax.scm | 13 ++++++++----- test/core.jl | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 0a7a58c1dcc78..dfab8c081260b 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1403,16 +1403,19 @@ ;; a.b = (let ((a (cadr (cadr e))) (b (caddr (cadr e))) - (rhs (caddr e))) + (rhs (expand-forms (caddr e)))) (let ((aa (if (atom? a) a (make-jlgensym))) - (bb (if (or (atom? b) (quoted? b)) b (make-jlgensym)))) + (bb (if (or (atom? b) (quoted? b)) b (make-jlgensym))) + (rr (if (atom? rhs) rhs (make-jlgensym)))) `(block - ,.(if (eq? aa a) '() `((= ,aa ,(expand-forms a)))) - ,.(if (eq? bb b) '() `((= ,bb ,(expand-forms b)))) + ,.(if (eq? aa a) '() `((= ,aa ,(expand-forms a)))) + ,.(if (eq? bb b) '() `((= ,bb ,(expand-forms b)))) + ,.(if (eq? rr rhs) '() `((= ,rr ,rhs))) (call (top setfield!) ,aa ,bb (call (top convert) (call (top fieldtype) (call (top typeof) ,aa) ,bb) - ,(expand-forms rhs))))))) + ,rr)) + ,rr)))) ((tuple) ;; multiple assignment diff --git a/test/core.jl b/test/core.jl index 3667edf77c5a5..1b599193c1c3b 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3647,3 +3647,7 @@ end # issue #14564 @test isa(object_id(Tuple.name.cache), Integer) + +# issue #14691 +type T14691; a::UInt; end +@test (T14691(0).a = 0) === 0