Bug 15303 - Redundant cast false positive
Summary: Redundant cast false positive
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: Trunk
Hardware: PC Linux
: Normal normal
Target Milestone: master
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-10-09 11:50 UTC by Andres G. Aragoneses
Modified: 2013-10-14 04:27 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 Andres G. Aragoneses 2013-10-09 11:50:37 UTC
Steps to reproduce:
1. Clone https://github.com/mono/gtk-sharp/ and open its main .sln solution.
2. Go to file parser/gapi-fixup.cs, line 103.

Current results: (IHasXmlNode) is marked as grey, as in "not needed".
Expected results: shouldn't be marked as redundant (because if you remove the cast, compilation fails with ./gapi-fixup.cs(103,47): error CS1061: Type `System.Xml.XPath.XPathNavigator' does not contain a definition for `GetNode' and no extension method `GetNode' of type `System.Xml.XPath.XPathNavigator' could be found. Are you missing an assembly reference?
Comment 1 Mike Krüger 2013-10-10 02:06:10 UTC
It seems not to be part of the gtk sharp solution.

How do you open that file ?
Comment 2 Andres G. Aragoneses 2013-10-11 08:34:49 UTC
> It seems not to be part of the gtk sharp solution

Oh, sorry! What I did was to open manually via "File->Open" after opening the solution.

I guess the bug then is trying to apply CodeIssues to files that are not inside a project?
Comment 3 Andres G. Aragoneses 2013-10-12 04:50:36 UTC
So, forget about gtk-sharp, and here you have steps to reproduce with a minimal testcase:

1. Create a .cs file with the following content:

namespace CodeIssueBug {

	using System;
	using System.IO;
	using System.Xml;
	using System.Xml.XPath;

	public class Fixup  {

		public static int Main (string[] args)
		{
			XmlDocument api_doc = new XmlDocument ();
			XmlDocument meta_doc = new XmlDocument ();

			XPathNavigator meta_nav = meta_doc.CreateNavigator ();
			XPathNavigator api_nav = api_doc.CreateNavigator ();

			XPathNodeIterator copy_iter = meta_nav.Select ("/metadata/copy-node");
			while (copy_iter.MoveNext ()) {
				string path = copy_iter.Current.GetAttribute ("path", String.Empty);
				XPathExpression expr = api_nav.Compile (path);
				string parent = copy_iter.Current.Value;
				XPathNodeIterator parent_iter = api_nav.Select (parent);
				bool matched = false;
				while (parent_iter.MoveNext ()) {
					XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
					XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
					while (path_iter.MoveNext ()) {
						XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
						parent_node.AppendChild (node.Clone ());
					}
					matched = true;
				}
				if (!matched)
					Console.WriteLine ("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
			}

			return 0;
		}
	}
}

2. Open monodevelop.
3. Open the single file above in monodevelop (without a solution or a project).

Current results: two casts to IHasXmlNode are marked as grey (which means CodeIssues are being analyzed).

Expected results: CodeIssues should not be analyzed?
Comment 4 Mike Krüger 2013-10-12 04:57:38 UTC
I see - maybe I turn off code issues in files without project.
(But anyways this issue needs to be patched)
Comment 5 Mike Krüger 2013-10-14 04:27:33 UTC
I turned off the code issues for single file projects.