mulint icon indicating copy to clipboard operation
mulint copied to clipboard

mulint only detects function calls that are used as statements, not in expressions

Open simonrad opened this issue 1 year ago • 0 comments

Hi, thank you for writing this linter, as I could not find anything similar anywhere else!

I notice that mulint seems to only traverse function calls that are written as simple statements where the return value is not used. So if a function call is used in an expression then mulint will ignore it.

For example, mulint can detect this deadlock:

type someStruct struct {
  m sync.RWMutex
}

func (s *someStruct) A() {
  s.m.RLock()
  s.B()
  s.m.RUnlock()
}

func (s *someStruct) B() bool {
  s.m.RLock() // This is a recursive lock and it should be detected by this tool
  s.m.RUnlock()
  return true
}

...but not this one:

type someStruct struct {
  m sync.RWMutex
}

func (s *someStruct) A() {
  s.m.RLock()
  v := s.B()           // ***** This is the only difference. *****
  fmt.Println(v)
  s.m.RUnlock()
}

func (s *someStruct) B() bool {
  s.m.RLock() // This is a recursive lock and it should be detected by this tool
  s.m.RUnlock()
  return true
}

simonrad avatar Nov 15 '23 20:11 simonrad