Bug 11492 - Auto-Fix for remove redundant assignment have issues in some cases
Summary: Auto-Fix for remove redundant assignment have issues in some cases
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:
Depends on:
Blocks:
 
Reported: 2013-03-31 16:15 UTC by Ciprian Khlud
Modified: 2013-04-04 06:04 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-03-31 16:15:10 UTC
Steps to reproduce the problem:

Start with this code:
class TestClass
{
	void TestMethod ()
	{
		int i = 1;
	}
}
Expected result:

Actual result:

class TestClass
{
	void TestMethod ()
	{
	}
}
class TestClass
{
	void TestMethod ()
	{
		int i;
	}
}

A similar issue is here:
using System;
class TestClass
{
	TestClass  Func () { return null; }
	void TestMethod ()
	{
		var a = Func ();
	}
}
Is ignored, when the simplification should work and remove 'a' variable:
using System;
class TestClass
{
	TestClass  Func () { return null; }
	void TestMethod ()
	{
		Func ();
	}
}
Comment 1 Ciprian Khlud 2013-03-31 16:19:24 UTC
Again it seems that it has many New-Line diff, I address both of the issues in this commit: https://github.com/ciplogic/NRefactory/commit/102488fa47429a670577bff78162591dcb5938ce

I've changed the unit tests accordingly and all tests seem to pass. I've added a new visitor that will look for the variable usages for ref/out names in all possible cases where it can be defined so it will make the smartest refactor based on the capabilities.
Comment 2 Ciprian Khlud 2013-03-31 16:26:43 UTC
I remember I've wrote a similar issue here with bug #10733 . 
This commit fixes issue #10733 and is a bit more aggressive in removal of variables.
Comment 3 Mike Krüger 2013-04-02 05:03:19 UTC
Can you try to fix the new lines ? This diff isn't really readable :/
Comment 6 Mike Krüger 2013-04-04 05:53:08 UTC
I added the fix.

btw. are you using vs.net ? The bracket style changed as well - please try to avoid changing bracket styles / line endings in conjunction with functional fixes. This really messes up change history - it will be very difficult to read change logs.
Comment 7 Ciprian Khlud 2013-04-04 06:00:47 UTC
Yes, I'm using the VS.Net with default settings and R# (with default settings).

I think that the changes in ending are made by R# because I do have the behavior to cut a section of the code and re-paste it as R# will reformat the code after paste. I will try to avoid R# formatting which I think is at fault. 

Thank you for being so patient!
Comment 8 Mike Krüger 2013-04-04 06:04:38 UTC
I'm not patient - just lazy :).

I really want to improve formatting in monodevelop - formatting is an interresting problem not really 'solved' well in current development environments. MonoDevelop destroys formatting as well atm when loading projects written in vs.net (with and without R#).

It's an annoying behaviour - but people using the development environments want that their code is formatted. It doesn't matter for the users how it is formatted (allman or K&R both work). Maybe we should do a formatting detection for monodevelop. MD is a bit better than VS.NET because we're writing our formatting settings inside the project file (that's why NRefactory has a different style than monodevelop). But we're far from beeing perfect :/