Skip to content

Detecting Liskov substitution principle violation (5th defect type)#51

Merged
nikololiahim merged 28 commits intomasterfrom
liskov_substitution_principle_violation
May 15, 2022
Merged

Detecting Liskov substitution principle violation (5th defect type)#51
nikololiahim merged 28 commits intomasterfrom
liskov_substitution_principle_violation

Conversation

@Leosimetti
Copy link
Copy Markdown
Contributor

@Leosimetti Leosimetti commented Apr 18, 2022

This PR contains the following changes:

  1. Implementation of the analyzer for the 5th defect type;
  2. Corresponding Unit-tests of the functionality;
  3. Improvements of the logic extraction mechanism: Closes (3rd type) An error in the long chain of call #35 and Closes (3rd type) An error in the chain of inheritance  #36 ;
  4. Refactoring of the analysis package;
  5. API for polystat.

Defect description

The definition of the Liskov substitution principle is as follows:

The principle defines that objects of a superclass shall be replaceable with objects of its subclasses without breaking the application.

We focus on one specific constraint that Liskov substitution principle enforces:

A subtype is not substitutable for its super type if it strengthens its operations' preconditions, or weakens its operations' postconditions.

Example of the defect

[] > base
  [self x] > f
    seq > @
      assert (x.less 9)
      x.add 1
[] > derived
  base > @
  [self x] > f
    seq > @
      assert (x.greater 9)
      x.sub 1

In this example, the redefinition of method f in the derived object changes the original input domain of argument x from (-inf, 9) to (9, inf). This is a strengthening of the preconditions on method f, which is a violation of the Liskov substitution principle.

Documentation: https://hackmd.io/@_2BO8tPVRp6UE5c1RTpY-Q/rJZrkGNrc.

Leosimetti and others added 20 commits April 18, 2022 02:49
…de with and without defects

Co-Authored-By: Mihail Olokin <45356788+nikololiahim@users.noreply.github.com>
…ological sort

Also, created an opportunity to support cases with mutual recursion.
Implementation detects functions that are problematic and replaces bad calls with stubs
Comment thread analysis/src/test/scala/org/polystat/odin/analysis/LiskovPrincipleTests.scala Outdated
@nikololiahim nikololiahim merged commit 8a05faf into master May 15, 2022
@nikololiahim nikololiahim deleted the liskov_substitution_principle_violation branch May 15, 2022 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(3rd type) An error in the chain of inheritance (3rd type) An error in the long chain of call

2 participants