From f80d9b9a0293ccd03b96aafaee4a9bce9d81d96c Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 28 Feb 2019 12:32:58 -0600 Subject: [PATCH] Handle expressions that lower to nothing --- src/JuliaInterpreter.jl | 4 +++- test/interpret.jl | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/JuliaInterpreter.jl b/src/JuliaInterpreter.jl index 989b37ede573e8..ebf29650a683c5 100644 --- a/src/JuliaInterpreter.jl +++ b/src/JuliaInterpreter.jl @@ -388,7 +388,9 @@ function prepare_thunk(mod::Module, thunk::Expr, recursive=false) thunk = Meta.lower(mod, Expr(:block, nothing, thunk)) framecode = JuliaFrameCode(mod, thunk.args[1]) else - return prepare_thunk(mod, Meta.lower(mod, thunk), true) + lwr = Meta.lower(mod, thunk) + isa(lwr, Expr) && return prepare_thunk(mod, lwr, true) + return nothing end return prepare_locals(framecode, []) end diff --git a/test/interpret.jl b/test/interpret.jl index 629567e2fbfa35..5a8451cdff546c 100644 --- a/test/interpret.jl +++ b/test/interpret.jl @@ -270,3 +270,7 @@ let TT = Union{UInt8, Int8} pa = pointer(a) @interpret unsafe_store!(pa, 0x1, 2) end + +# Some expression can appear nontrivial but lower to nothing +@test isa(JuliaInterpreter.prepare_thunk(Main, :(@static if ccall(:jl_get_UNAME, Any, ()) == :NoOS 1+1 end)), Nothing) +@test isa(JuliaInterpreter.prepare_thunk(Main, :(Base.BaseDocs.@kw_str "using")), Nothing)