Skip to content

Commit 3de5b9a

Browse files
authored
Fix desugaring of const x::T = y for complex y (#59155)
Fix #59128 Assignment desugaring of `(const (= (|::| x T) rhs))` would pre-expand to, then re-expand `(const x ,(convert-for-type-decl rhs T))`, but two-arg (IR) const is expected to have a simple RHS---closure conversion doesn't recurse here (should it?), giving us partially-lowered IR, and hence our bug. Fix: Pre-expand to the one-arg AST const form `(const (= x ,(convert-for-type-decl rhs T)))` instead. This also gives us a `(latestworld)` we were missing before, so this lowering may have been originally intended.
1 parent 1f6eff1 commit 3de5b9a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,9 @@
16451645
(expand-forms
16461646
;; TODO: This behaviour (`const _:T = ...` does not call convert,
16471647
;; but still evaluates RHS) should be documented.
1648-
`(const ,(car e) ,(if (underscore-symbol? (car e))
1649-
rhs
1650-
(convert-for-type-decl rhs T #t #f))))
1648+
`(const (= ,(car e) ,(if (underscore-symbol? (car e))
1649+
rhs
1650+
(convert-for-type-decl rhs T #t #f)))))
16511651
(expand-forms
16521652
`(block ,@(cdr e)
16531653
;; TODO: When x is a complex expression, this acts as a

test/syntax.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,24 @@ end
43054305
@test letf_57470(3) == 5
43064306
@test letT_57470 === Int64
43074307

4308+
# Closure conversion should happen on const assignment rhs
4309+
module M59128
4310+
using Test
4311+
const x0::Int = (()->1)()
4312+
global x1::Int = (()->1)()
4313+
global const x2::Int = (()->1)()
4314+
const global x3::Int = (()->1)()
4315+
@test x0 === x1 === x2 === x3 === 1
4316+
let g = 1
4317+
global x4::Vector{T} where {T<:Number} = let; (()->[g])(); end
4318+
const global x5::Vector{T} where {T<:Number} = let; (()->[g])(); end
4319+
global const x6::Vector{T} where {T<:Number} = let; (()->[g])(); end
4320+
end
4321+
@test x4 == x5 == x6 == [1]
4322+
const letT_57470{T} = (()->Int64)()
4323+
@test letT_57470 == Int64
4324+
end
4325+
43084326
end # M57470_sub
43094327

43104328
# lowering globaldecl with complex type

0 commit comments

Comments
 (0)