Bug 11866 - Should be a Code Issue in case of duplicate method bodies
Summary: Should be a Code Issue in case of duplicate method bodies
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: Trunk
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Mike Krüger
Depends on:
Reported: 2013-04-19 15:16 UTC by Ciprian Khlud
Modified: 2013-05-02 05:54 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ciprian Khlud 2013-04-19 15:16:19 UTC
If in the same file, there are two (non empty) method bodies that are the same, and the method have the same parameters and return types, there should be a way to notice this code duplication and to rewrite it as a call of the other method.

class T
   void Hello(){ 
     Console.WriteLine("Hello world");

   void $Priviet() {
     Console.WriteLine("Hello world"); 

class T
   void Hello() {
      Console.WriteLine("Hello world"); }

   void $Priviet(){ 
     Hello(); }
Comment 1 Ciprian Khlud 2013-04-24 15:43:00 UTC
Added a sample code that works for most cases (including the shown one in the bug) here:

Some cases are not yet solved like:
- non void methods are not invoked with prefixed return ...
- there are some end of line issues in the unit test

The gathering of method bodies is done in a visiting fashion and it is reset if another class definition is found. This means that if you have a case like:
void Method1() {...}
class InnerClass{...}
void Method2() { ...}

Method2() will not be detected as a duplicate. But if the same code is:

class InnerClass{...}
void Method1() {...}
void Method2() { ...}

the duplicate will be found.
Comment 2 Mike Krüger 2013-05-02 05:54:59 UTC