Skip to content

Commit

Permalink
Replace within-module eval with hygienic eval
Browse files Browse the repository at this point in the history
The use of eval makes precompilation funky due to the within-module eval
during precompilation. Evaluation within the calling module doesn't work
either because macro hygiene hasn't been applied yet.

The solution: apply hygiene ourselves then eval within the calling
module.
  • Loading branch information
tecosaur committed Oct 23, 2023
1 parent 4777e60 commit 5536500
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/stylemacro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ macro styled_str(raw_content::String)
nothing
end

hygienic_eval(expr) = Core.eval(__module__, Expr(:var"hygienic-scope", expr, @__MODULE__))

function addpart!(state, stop::Int)
if state.point[] > stop+state.offset[]+ncodeunits(state.content[stop])-1
return state.point[] = nextind(state.content, stop) + state.offset[]
Expand Down Expand Up @@ -537,7 +539,7 @@ macro styled_str(raw_content::String)
if needseval
:(Pair{Symbol, Any}(:face, $face))
else
Pair{Symbol, Any}(:face, eval(face))
Pair{Symbol, Any}(:face, hygienic_eval(face))
end))
end

Expand Down Expand Up @@ -669,7 +671,7 @@ macro styled_str(raw_content::String)
elseif state.interpolated[]
:(annotatedstring($(state.parts...)))
else
annotatedstring(map(eval, state.parts)...) |> Base.annotatedstring_optimize!
annotatedstring(map(hygienic_eval, state.parts)...) |> Base.annotatedstring_optimize!
end
end

Expand Down

0 comments on commit 5536500

Please sign in to comment.