polystat / odin

Object Dependency Inspector
10 stars 2 forks source link

Detecting direct access to base class state (4th defect type) #48

Closed Leosimetti closed 2 years ago

Leosimetti commented 2 years ago

This PR contains the following changes:

  1. Implementation of the analyzer for the 4th defect type;
  2. Corresponding Unit-tests of the functionality;
  3. API for polystat.

Example of the defect

The proper way to change the state in the subclass b would be:

[] > a
  memory > state
  [self new_state] > update_state
    seq > @
      state.write new_state
      state
[] > b
  a > @
  [self new_state] > change_state_plus_two
    new_state.add 2 > tmp
    seq > @
      self.update_state self tmp
      state

An improper way to achieve the same functionality in subclass bad:

[] > a
  memory > state
  [self new_state] > update_state
    seq > @
      self.state.write new_state
      self.state
[] > bad
  a > @
  [self new_state] > change_state_plus_two
    seq > @
      self.state.write (new_state.add 2) 
      self.state

More detailed information about the problem statement and implementation is available here.

fizruk commented 2 years ago

Please, add example(s) with explanation to the description of the PR.