Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible method call error showing up on some simple code #256

Closed
dmalyuta opened this issue Feb 2, 2021 · 4 comments · Fixed by #257
Closed

Possible method call error showing up on some simple code #256

dmalyuta opened this issue Feb 2, 2021 · 4 comments · Fixed by #257
Assignees
Labels
Milestone

Comments

@dmalyuta
Copy link

dmalyuta commented Feb 2, 2021

I am using:

  • OS: Ubuntu 20.04.1 LTS
  • Julia: 1.5.3
  • StaticLint: [b3cc710f] StaticLint v7.0.0
  • SymbolServer: [cf896787] SymbolServer v6.0.1

The following code seems problematic:

abstract type MyType end

mutable struct Bar<:MyType
    val::Integer
end

function multiply!(x::T, y::Integer)::Nothing where {T<:MyType}
    x.val *= y
    return nothing
end

z = Bar(2)
multiply!(z, 3)

println(z.val)

Here is what StaticLint shows:
image

It seems that StaticLint has a history of issues with this kind of error: here, here, and here

@davidanthoff davidanthoff added this to the Triage milestone Feb 2, 2021
@pfitzseb
Copy link
Member

pfitzseb commented Feb 2, 2021

I think there are two issues here:

  1. function multiply!(x::T, y::Integer)::Nothing where {T<:MyType} (needs both the where clause and return type annotation) being treated as a call.
  2. We can't infer the type of z.

So

function multiply!(x::T, y::Integer) where T <: MyType # no return type annotation
    x.val *= y
    return nothing
end

function f(z::Bar) # make sure we can figure out the type of z
    multiply!(z, 3)
end

works just fine.

@dmalyuta
Copy link
Author

dmalyuta commented Feb 2, 2021

Just to be clear, your point 1 is a current issue with StaticLint? Do we agree that function multiply!(x::T, y::Integer)::Nothing where {T<:MyType} should be interpreted as a function signature? If I remove the ::Nothing, then the following code works without any errors reported by StaticLint:

abstract type MyType end

mutable struct Bar<:MyType
    val::Integer
end

function multiply!(x::T, y::Integer) where {T<:MyType}
    x.val *= y
    return nothing
end

z = Bar(2)
multiply!(z, 3)

println(z.val)

@ZacLN
Copy link
Contributor

ZacLN commented Feb 2, 2021

It's just a bug, I'll fix it

@dmalyuta
Copy link
Author

dmalyuta commented Feb 3, 2021

Hmm I think that the fix by @ZacLN has the inadvertent side-effect of suppressing warnings such as An argument is included in a function signature but not used within its body. when the function signature contains the where {T<:...} syntax. For example, for the following function StaticLint does not show any warnings:

function multiply!(x::T, y::Integer, z::Integer)::Nothing where {T<:MyType}
    x.val *= y
    return nothing
end

On the other hand, the following function does show a warning that the z argument is not used within its body:

function multiply!(x::Bar, y::Integer, z::Integer)::Nothing
    x.val *= y
    return nothing
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants