Skip to content

Commit

Permalink
add warning for #12 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo authored Dec 2, 2023
1 parent 27a701d commit 803d17c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/match/scan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function EmitInfo(mod::Module, value, body, source=nothing)
if stmt isa LineNumberNode
line_info = stmt
elseif Meta.isexpr(stmt, :call) && stmt.args[1] === :(=>)
push!(cases, expr2pattern(stmt.args[2]))
push!(cases, warn_expr2pattern(mod, stmt.args[2]))
push!(exprs, stmt.args[3])
else
throw(SyntaxError("invalid pattern table: $body"; source=line_info))
Expand All @@ -37,6 +37,13 @@ function EmitInfo(mod::Module, value, body, source=nothing)
)
end

function warn_expr2pattern(mod::Module, expr)
if expr isa Symbol && isdefined(mod, expr)
@warn "you are using a variable name that is already defined in the module: $(expr)"
end
return expr2pattern(expr)
end

function split_toplevel_or(cases::Vector{Pattern.Type}, exprs::Vector{Any})
new_cases, new_exprs = Pattern.Type[], []
for (case, expr) in zip(cases, exprs)
Expand Down

0 comments on commit 803d17c

Please sign in to comment.