Possible method call error -> docstring above struct fields

JADekker
Wed, 12 Feb 2025 12:20:56 +0000
New to Julia

In VS Code, I keep getting that the linter returns a “possible method call error” if I try to create an instance of a struct with fields to which I’ve added docstrings; see the below MWE where the linter doesn’t complain about Foo1 but does complain about Foo2. Is the only way to avoid this to put the full docstring above the definition of the struct (Foo3), or is there some easy way of doing this? In my project I have structs with roughly 10 fields and I would like to keep the relevant descriptions close to their fields for easy reference.

struct Foo1{T<:Real}
    x::T
end
struct Foo2{T<:Real}
    """Same as above, but with a docstring"""
    x::T
end

"""Same as above, but with a docstring above the struct"""
struct Foo3{T<:Real}
    x::T
end

function Test()
    Foo1(1)
    Foo2(1) # Triggers the linter
    #Foo2(1, 1) doesn't trigger the linter (but is not a valid call!)
    Foo3(1)
end

Test()

5 posts - 2 participants