Skip to content

Commit

Permalink
Merge pull request #58 from julia-vscode/inclloop
Browse files Browse the repository at this point in the history
safety check for include loops
  • Loading branch information
ZacLN authored Dec 17, 2019
2 parents dec3666 + 7db0983 commit 1b1cc5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/StaticLint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bindingof(m::Meta) = m.binding
mutable struct State{T}
file::T
targetfile::Union{Nothing,T}
included_files::Vector{String}
scope::Scope
delayed::Bool
urefs::Vector{EXPR}
Expand Down Expand Up @@ -140,12 +141,18 @@ function followinclude(x, state::State)
path = ""
end
if !isempty(path)
if path in state.included_files
seterror!(x, IncludeLoop)
return
end
oldfile = state.file
state.file = getfile(state.server, path)
push!(state.included_files, getpath(state.file))
setroot(state.file, getroot(oldfile))
setscope!(getcst(state.file), nothing)
state(getcst(state.file))
state.file = oldfile
pop!(state.included_files)
else
seterror!(x, MissingFile)
end
Expand Down
3 changes: 3 additions & 0 deletions src/linting/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ PointlessOR,
PointlessAND,
UnusedBinding,
InvalidTypeDeclaration,
IncludeLoop,
MissingFile)


const LintCodeDescriptions = Dict{LintCodes,String}(
IncorrectCallNargs => "An incorrect number of function arguments has been passed.",
IncorrectIterSpec => "A loop iterator has been used that will likely error.",
Expand All @@ -21,6 +23,7 @@ const LintCodeDescriptions = Dict{LintCodes,String}(
PointlessAND => "The first argument of a `&&` call is `false`.",
UnusedBinding => "The variable name has been bound but not used.",
InvalidTypeDeclaration => "A non-DataType has been used in a type declaration statement.",
IncludeLoop => "Loop detected, this file has already been included.",
MissingFile => "The included file can not be found."
)

Expand Down
2 changes: 1 addition & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ getsymbolserver(server::FileServer) = server.symbolserver
function scopepass(file, target = nothing)
server = file.server
setscope!(getcst(file), Scope(nothing, getcst(file), Dict(), Dict{String,Any}("Base" => getsymbolserver(server)["Base"], "Core" => getsymbolserver(server)["Core"]), false))
state = State(file, target, scopeof(getcst(file)), false, EXPR[], server)
state = State(file, target, [getpath(file)], scopeof(getcst(file)), false, EXPR[], server)
state(getcst(file))
for uref in state.urefs
s = retrieve_delayed_scope(uref)
Expand Down

0 comments on commit 1b1cc5a

Please sign in to comment.