julia-vscode / StaticLint.jl

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

False positive: Adding new constructors to aliases of parameterized types #394

Open dzhang314 opened 1 month ago

dzhang314 commented 1 month ago

Consider the following Julia code:

module M

struct Container{T}
    value::T
end

const IntContainer = Container{Int}

function IntContainer(x::Float64)
    return IntContainer(round(Int, x))
end

end # module M

This yields blue squiggles under the definition of function IntContainer(x::Float64) with the following message:

Cannot define function ; it already has a value. Julia(CannotDefineFuncAlreadyHasValue)

This pattern occurs a lot in my package MultiFloats.jl, where I have a generic type MultiFloat{T,N}, and then I define aliases const Float64x2 = MultiFloat{Float64,2} with their own constructors.