Skip to content

Commit 40ec17c

Browse files
committed
Add isdefinedglobal builtin
JuliaLang/julia#54999, JuliaLang/julia#56985
1 parent aea8fe5 commit 40ec17c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/closure_conversion.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ function _convert_closures(ctx::ClosureConversionCtx, ex)
337337
elseif binfo.is_always_defined || is_self_captured(ctx, var)
338338
# Captured but unboxed vars are always defined
339339
@ast ctx ex true::K"Bool"
340+
elseif kind(var) == K"globalref"
341+
# Normal isdefined won't work for globals (#56985)
342+
@ast ctx ex [K"call"
343+
"isdefinedglobal"::K"core"
344+
[ "thismodule"::K"Identifier" ]
345+
false::K"Bool"]
340346
else
341347
ex
342348
end

src/desugaring.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ function expand_abstract_or_primitive_type(ctx, ex)
34093409
[K"global" name]
34103410
[K"if"
34113411
[K"&&"
3412-
[K"isdefined" name]
3412+
[K"call" "isdefinedglobal"::K"core" name false::K"Bool"]
34133413
[K"call" "_equiv_typedef"::K"core" name newtype_var]
34143414
]
34153415
nothing_(ctx, ex)
@@ -3936,7 +3936,7 @@ function expand_struct_def(ctx, ex, docs)
39363936
[K"=" struct_name newtype_var]
39373937
[K"call"(supertype) "_setsuper!"::K"core" newtype_var supertype]
39383938
[K"if"
3939-
[K"isdefined" global_struct_name]
3939+
[K"call" "isdefinedglobal"::K"core" global_struct_name false::K"Bool"]
39403940
[K"if"
39413941
[K"call" "_equiv_typedef"::K"core" global_struct_name newtype_var]
39423942
[K"block"

0 commit comments

Comments
 (0)