Skip to content

Commit e5faf18

Browse files
mlechuKristofferC
authored andcommitted
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. (cherry picked from commit 3de5b9a)
1 parent 3cab711 commit e5faf18

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
@@ -1642,9 +1642,9 @@
16421642
(expand-forms
16431643
;; TODO: This behaviour (`const _:T = ...` does not call convert,
16441644
;; but still evaluates RHS) should be documented.
1645-
`(const ,(car e) ,(if (underscore-symbol? (car e))
1646-
rhs
1647-
(convert-for-type-decl rhs T #t #f))))
1645+
`(const (= ,(car e) ,(if (underscore-symbol? (car e))
1646+
rhs
1647+
(convert-for-type-decl rhs T #t #f)))))
16481648
(expand-forms
16491649
`(block ,@(cdr e)
16501650
;; 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
@@ -4236,6 +4236,24 @@ end
42364236
@test letf_57470(3) == 5
42374237
@test letT_57470 === Int64
42384238

4239+
# Closure conversion should happen on const assignment rhs
4240+
module M59128
4241+
using Test
4242+
const x0::Int = (()->1)()
4243+
global x1::Int = (()->1)()
4244+
global const x2::Int = (()->1)()
4245+
const global x3::Int = (()->1)()
4246+
@test x0 === x1 === x2 === x3 === 1
4247+
let g = 1
4248+
global x4::Vector{T} where {T<:Number} = let; (()->[g])(); end
4249+
const global x5::Vector{T} where {T<:Number} = let; (()->[g])(); end
4250+
global const x6::Vector{T} where {T<:Number} = let; (()->[g])(); end
4251+
end
4252+
@test x4 == x5 == x6 == [1]
4253+
const letT_57470{T} = (()->Int64)()
4254+
@test letT_57470 == Int64
4255+
end
4256+
42394257
end # M57470_sub
42404258

42414259
# lowering globaldecl with complex type

0 commit comments

Comments
 (0)