Skip to content

Commit

Permalink
Merge pull request #35 from RelationalAI/improved-array
Browse files Browse the repository at this point in the history
Improved checks for arrays
  • Loading branch information
bergel authored Mar 11, 2024
2 parents 443e240 + 0a1732f commit e5f2db8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/linting/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ function check_all(x::EXPR, opts::LintOptions, env::ExternalEnv, markers::Dict{S
markers[:function] = fetch_value(x, :IDENTIFIER)
end

if headof(x) === :macrocall
markers[:macrocall] = fetch_value(x, :IDENTIFIER)
end

# Do checks
opts.call && check_call(x, env)
opts.iter && check_loop_iter(x, env)
opts.nothingcomp && check_nothing_equality(x, env)
opts.constif && check_if_conds(x)
opts.lazy && check_lazy(x)
opts.datadecl && check_datatype_decl(x, env)
opts.typeparam && check_typeparams(x)
opts.typeparam && check_typeparams(x, markers)
opts.modname && check_modulename(x)
opts.pirates && check_for_pirates(x)
opts.useoffuncargs && check_farg_unused(x)
Expand All @@ -171,6 +175,7 @@ function check_all(x::EXPR, opts::LintOptions, env::ExternalEnv, markers::Dict{S
# Do some cleaning
headof(x) === :const && delete!(markers, :const)
headof(x) === :function && delete!(markers, :function)
headof(x) === :macrocall && delete!(markers, :macrocall)
end

function _typeof(x, state)
Expand Down Expand Up @@ -793,7 +798,10 @@ end

isunionfaketype(t::SymbolServer.FakeTypeName) = t.name.name === :Union && t.name.parent isa SymbolServer.VarRef && t.name.parent.name === :Core

function check_typeparams(x::EXPR)
function check_typeparams(x::EXPR, markers::Dict{Symbol,String})
haskey(markers, :macrocall) && markers[:macrocall] == "@match" && return
haskey(markers, :macrocall) && markers[:macrocall] == "@matchrule" && return

if iswhere(x)
for i in 2:length(x.args)
a = x.args[i]
Expand Down
4 changes: 4 additions & 0 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ check(::Ptr_Extension, x::EXPR) = generic_check(x, "Ptr{hole_variable}(hole_vari
function check(::ArrayWithNoType_Extension, x::EXPR, markers::Dict{Symbol,String})
haskey(markers, :filename) || return
contains(markers[:filename], "src/Compiler") || return

haskey(markers, :macrocall) && markers[:macrocall] == "@match" && return
haskey(markers, :macrocall) && markers[:macrocall] == "@matchrule" && return

generic_check(x, "[]", "Need a specific Array type to be provided.")
end

Expand Down
49 changes: 47 additions & 2 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ function lint_test(source::String, expected_substring::String; verbose=true, dir
return result
end

function lint_has_error_test(source::String, verbose=false)
function count_lint_errors(source::String, verbose=false; directory::String = "")
io = IOBuffer()
run_lint_on_text(source; io=io)
run_lint_on_text(source; io, directory)
result = String(take!(io))
all_lines = split(result, "\n")

verbose && @info result
# We remove decorations
return length(filter(l->startswith(l, "Line "), all_lines))
end


function lint_has_error_test(source::String, verbose=false; directory::String = "")
io = IOBuffer()
run_lint_on_text(source; io, directory)
result = String(take!(io))
all_lines = split(result, "\n")

Expand Down Expand Up @@ -460,6 +472,39 @@ end
directory = "src/Compiler/")
end

@testset "Array with no specific type 03" begin
source = """
function f()
@matchrule bindings_empty() =
Bindings([], _::Missing) => CoreBindings([])
@matchrule and_to_true() =
And([], annos) => BoolConstant(true, annos)
@matchrule and_singleton() =
And([f], annos) => f
@match CoreRelAbstract(bs2, [], as2) = e2
@matchrule and_to_true() =
And([], annos) => BoolConstant(true, annos)
@matchrule exists_empty() =
Exists(e, _) where is_definitely_empty_expr(e) =>
slice_to_false(input_val)
f = []
end
"""
count_errors = count_lint_errors(source; directory = "src/Compiler/")
@test count_errors == 1
@test lint_test(
source,
"Line 19, column 9: Need a specific Array type to be provided.";
directory = "src/Compiler")
end



@testset "in, equal, haskey, uv_" begin
source = """
function f()
Expand Down

0 comments on commit e5f2db8

Please sign in to comment.