File tree 2 files changed +22
-2
lines changed 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -761,8 +761,10 @@ function lookup_global_refs!(ex::Expr)
761
761
for (i, a) in enumerate (ex. args)
762
762
ex. head == :(= ) && i == 1 && continue # Don't look up globalrefs on the LHS of an assignment (issue #98)
763
763
if isa (a, GlobalRef)
764
- r = getfield (a. mod, a. name)
765
- ex. args[i] = QuoteNode (r)
764
+ if isdefined (a. mod, a. name) && isconst (a. mod, a. name)
765
+ r = getfield (a. mod, a. name)
766
+ ex. args[i] = QuoteNode (r)
767
+ end
766
768
elseif isa (a, Expr)
767
769
lookup_global_refs! (a)
768
770
end
Original file line number Diff line number Diff line change @@ -357,3 +357,21 @@ f113(;x) = x
357
357
@test length (locals) == 3
358
358
@test JuliaInterpreter. Variable (3 , :x , false ) in locals
359
359
end
360
+
361
+ @testset " getfield replacements" begin
362
+ f_gf (x) = false ? some_undef_var_zzzzzzz : x
363
+ @test @interpret f_gf (2 ) == 2
364
+
365
+ function g_gf ()
366
+ eval (:(z = 2 ))
367
+ return z
368
+ end
369
+ @test @interpret g_gf () == 2
370
+
371
+ global q_gf = 0
372
+ function h_gf ()
373
+ eval (:(q_gf = 2 ))
374
+ return q_gf
375
+ end
376
+ @test @interpret h_gf () == 2
377
+ end
You can’t perform that action at this time.
0 commit comments