Skip to content

Commit

Permalink
fix type inference for empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 16, 2025
1 parent e2a7208 commit 35b540d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,21 @@ function let_eval!(expr, let_block, m::Module, is_non_reactive::Bool = true)
end

# deterimine the variables that need to be evaluated to infer the type of the variable
function required_evals!(expr, vars::Set)
function required_evals!(expr, vars::Set, all_vars::Set)
expr isa LineNumberNode && return vars
expr = find_assignment(expr)
# @mixin statements are currently not evaluated
expr === nothing && return vars
if expr.args[1] isa Symbol
x = expr.args[1]
push!(vars, x)
push!(all_vars, x)
elseif expr.args[1] isa Expr && expr.args[1].head == :(::)
x = expr.args[1].args[1]
push!(all_vars, x)
end
MacroTools.postwalk(expr.args[end]) do ex
MacroTools.@capture(ex, x_[]) && push!(vars, x)
MacroTools.@capture(ex, x_[]) && x all_vars && push!(vars, x)
ex
end
return vars
Expand Down Expand Up @@ -454,7 +458,6 @@ end

macro var_storage(expr, handler = nothing)
m = __module__

expr = macroexpand(m, expr) |> MacroTools.flatten
if !isa(expr, Expr) || expr.head != :block
expr = quote $expr end
Expand All @@ -464,8 +467,9 @@ macro var_storage(expr, handler = nothing)

source = nothing
required_vars = Set()
all_vars = Set()
let_block = Expr(:block, :(_ = 0))
required_evals!.(expr.args, Ref(required_vars))
required_evals!.(expr.args, Ref(required_vars), Ref(all_vars))
add_brackets!.(expr.args, Ref(required_vars))
for e in expr.args
if e isa LineNumberNode
Expand Down

0 comments on commit 35b540d

Please sign in to comment.