Bug 11579 - Auto-Fix for remove redundant assignment have issues in some cases (Part II)
Summary: Auto-Fix for remove redundant assignment have issues in some cases (Part II)
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: Trunk
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
: 10733 ()
Depends on:
Blocks:
 
Reported: 2013-04-04 08:23 UTC by Ciprian Khlud
Modified: 2013-04-04 10:39 UTC (History)
1 user (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Ciprian Khlud 2013-04-04 08:23:56 UTC
Redundant variables with functions (and not only) do remove the assignments inside declaration but sometimes, it doesn't do it correctly in all cases, so I found a small case to isolate some other edge cases.  

using System;
class TestClass
{
	TestClass  Func () { return null; }
	void TestMethod ()
	{
		var a = Func ();
        a = 2;
	}
}

Actual result: (declaration of a is removed)

using System;
class TestClass
{
	TestClass  Func () { return null; }
	void TestMethod ()
	{
		Func ();
        a = 2;
	}
}

Expected result:

using System;
class TestClass
{
	TestClass  Func () { return null; }
	void TestMethod ()
	{
		TestClass a;
		Func ();
        a = 2;
	}
}

Added a commit (hopefully with good line endings) here that adds this extra unit test and make more type replacements:
https://github.com/ciplogic/NRefactory/commit/f806f635bee0304dfeba1e488575624226e1cb06
Comment 1 Mike Krüger 2013-04-04 08:53:15 UTC
Line endings are better - you're just messing up tabs with spaces :)
Comment 7 Mike Krüger 2013-04-04 10:39:13 UTC
*** Bug 10733 has been marked as a duplicate of this bug. ***