julia-vscode / StaticLint.jl

Static Code Analysis for Julia
Other
145 stars 28 forks source link

False positive in testset with anonymous function #362

Open schillic opened 1 year ago

schillic commented 1 year ago

The following reports Cannot define function ; it already has a value. in the line marked with a comment. But running the code works fine because, as the Note box here says, @testset creates a new scope. There is no warning when writing f(x) = 1 instead of the anonymous function in the first block.

using Test

@testset "1" begin
    f = x -> 1
    f(1)
end

@testset "2" begin
    f(x) = 2  # <- warning here
    f(2)
end