gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
390 stars 22 forks source link

Not able to detect inherited properties. #68

Closed jordan2175 closed 2 years ago

jordan2175 commented 2 years ago

If you have:

package house

type CommonProperties struct {
    RoomType string
    RoomSize string
}

And then you have:

package kitchen

type Kitchen struct {
    house.CommonProperties
    Seats int
    Stove bool
}

And then in package kitchen you try to do something like:

func (k *Kitchen) Something() {
    k.RoomType = "Kitchen"
}

This tool will give an error saying that RoomType is not a valid assignment.

gordonklaus commented 2 years ago

I am unable to reproduce this. Can you double check the source of your error and share the exact code that produces it as well as the exact error text?

jordan2175 commented 2 years ago

You can see the report on the Go Scorecard here: https://goreportcard.com/report/github.com/openplaybooks/libcacao

Nearly all of these errors are wrong. But if you look at the second entry libcacao/objects/workflow/ifcondition/ifcondition.go line 49 you can see this exact problem.

jordan2175 commented 2 years ago

It also says that some of the imports are ineffective, but they are part of importing properties into types. So without that import statements, it does not work nor does it compile.

gordonklaus commented 2 years ago

I downloaded your project and ran ineffassign against several of the files and I did not get any errors or warnings reported. The problem seems to be with how goreportcard.com is using this tool. I see there is an open issue there; maybe if you add your voice to it, it will get fixed sooner.

As a side note, I see that your project does not have a go.mod file. This may be problematic, as GOPATH mode is deprecated in favor of modules. This may be the reason for the import errors you see.

To be clear, none of the errors/warnings you see are ineffectual assignments (or they would say ineffectual assignment); they are problems loading the code (I'm not sure whether because goreportcard.com is using an old version of ineffassign, or what).

jordan2175 commented 2 years ago

Thanks! Sorry to bother you. I just have not yet added the mod file. I will do that.