Bug 17945 - Bad 'unnecessary cast' warning
Summary: Bad 'unnecessary cast' warning
Status: VERIFIED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2014-02-21 16:29 UTC by David Siegel
Modified: 2014-03-27 05:57 UTC (History)
2 users (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:
VERIFIED FIXED

Description David Siegel 2014-02-21 16:29:11 UTC
https://gist.github.com/dvdsgl/0b2ed63aaec29227a413

I have a primary constructor that takes an instance of a type X, and a secondary constructor that takes an instance of type Y : X. The secondary constructor calls the primary constructor using this(x as X), which is flagged as an 'unnecessary cast' warning. However, if you remove the cast, you get a 'constructor cannot call itself' error.
Comment 1 Mike Krüger 2014-02-24 02:53:06 UTC
fixed
Comment 2 Ram Chandra 2014-03-27 05:57:57 UTC
I have check this issue on following builds

Mac OS X 10.7.5
Xamarin Studio: 4.2.4 (build 266)

I observed that when I build the following code, it doesn't flag any "unnecessary cast" warning.

namespace bug_17945
{
	class MainClass
	{

		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!"); 
			//Test objTest = new Test ("Test");
			Console.ReadKey ();
		}
	}
	class Test{
		public Test(object o)
		{
		}

		public Test(string o): this (o as object )
		{
		}
	}
}

I also observed that, if I remove the cast, I  got a "constructor cannot call itself" error.
ex : public Test(string o): this (o )
		{
		}

Screencast: http://www.screencast.com/t/zZiErQfEmig

Please let me know if missing anything?