aviatesk / JET.jl

An experimental code analyzer for Julia. No need for additional type annotations.

Home Page:https://aviatesk.github.io/JET.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple syntax error not reported by report_file

stemann opened this issue · comments

The simple syntax error ("is") in elseif is Sys.iswindows(platform) was not caught by report_file using JET v0.8.20 on Julia v1.9.3:

function is_supported(platform)
    if Sys.islinux(platform)
        return arch(platform) in ["x86_64", "aarch64", "powerpc64le"]
    elseif is Sys.iswindows(platform)
        return false
    else
        return false    
    end
end

Is this expected?

It's expected, since your code is actually a valid Julia program.

    elseif is Sys.iswidows(platform)
        return false

is equivalent to

    elseif is
        Sys.iswindows(platform)
        return false

... but shouldn't the is symbol then be reported as not being defined...?

... a "few" minutes later... :-)

To answer my own question: JET.report_file reports concrete errors - a function definition (even with syntax errors) is not checked in that regard: This reports no errors:

function is_true(foo)
    if foo
        return true
    elseif is foo
        return false
    end
end

Whereas, this reports "is is not defined" (due to the concrete is_true(false) call):

function is_true(foo)
    if foo
        return true
    elseif is foo
        return false
    end
end

is_true(false)

On the contrary, if the function definition had been in a package, JET.report_package (and StaticLint) would report the error (and so would JET.report_file(...; analyze_from_definitions = true)).