From 94ba5427f3d06cc95b208758f2e6ff90947cea2d Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Thu, 22 Apr 2021 12:52:25 +0200 Subject: [PATCH] fix #476: isdefined with QuoteNode (#477) --- src/interpret.jl | 5 ++++- test/interpret.jl | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/interpret.jl b/src/interpret.jl index ba26275a7582c4..23c945a2da89c4 100644 --- a/src/interpret.jl +++ b/src/interpret.jl @@ -415,14 +415,17 @@ function check_isdefined(frame, @nospecialize(node)) data = frame.framedata if isa(node, SlotNumber) return data.locals[node.id] !== nothing + elseif isa(node, Core.Compiler.Argument) # just to be safe, since base handles this + return data.locals[node.n] !== nothing elseif isexpr(node, :static_parameter) return isassigned(data.sparams, node.args[1]::Int) elseif isa(node, GlobalRef) return isdefined(node.mod, node.name) elseif isa(node, Symbol) return isdefined(moduleof(frame), node) + else # QuoteNode or other implicitly quoted object + return true end - error("unrecognized isdefined node ", node) end # For "profiling" where JuliaInterpreter spends its time. See the commented-out block diff --git a/test/interpret.jl b/test/interpret.jl index b5619f3e5d1691..b6ac1368333319 100644 --- a/test/interpret.jl +++ b/test/interpret.jl @@ -746,3 +746,15 @@ end @testset "#466 parametric_type_to_expr" begin @test JuliaInterpreter.parametric_type_to_expr(Array) == :(Core.Array{T, N}) end + +@testset "#476 isdefined QuoteNode" begin + f() = !true + + @generated function g() + ci = @code_lowered f() + ci.code[1] = Expr(:isdefined, QuoteNode(Float64)) + return ci + end + + @test @interpret(g()) === true +end