Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V7002. The body of a function is...
menu mobile close menu
Additional information
toggle menu Contents

V7002. The body of a function is fully equivalent to the body of another function.

Apr 03 2026

The analyzer has detected two functions with identical implementations. Although having two identical functions is not an error, they should still be reviewed.

The diagnostic rule detects the following error types:

class Point
{
  foo;
  bar;

  getFoo() { return foo; }
  getBar() { return foo; }
}

A typo causes two logically different functions to perform the same actions.

The fixed code:

class Point
{
  foo;
  bar;

  getFoo() { return foo; }
  getBar() { return bar; }
}

In the example, the identical bodies of the getFoo and getBar functions indicate an error. However, issuing warnings for all identical functions could result in many false positives. Therefore, the analyzer has a number of exceptions where a warning about identical function bodies is not required.

Some examples of exceptions:

  • the function immediately returns a value that is either a literal or this, for example, isXYZ() { return true; };
  • functions with identical bodies are repeated more than twice;
  • the function body consists only of the throw statement.