Bug 9617 - Incorrect "parameter can be demoted to base class" warning for arrays
Summary: Incorrect "parameter can be demoted to base class" warning for arrays
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 4.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-01-16 15:07 UTC by Mikayla Hutchinson [MSFT]
Modified: 2013-08-20 06:51 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 Mikayla Hutchinson [MSFT] 2013-01-16 15:07:18 UTC
object Foo (object[] arr)
{
	return arr [0];
}
Comment 1 Mike Krüger 2013-01-24 05:39:36 UTC
fixed
Comment 2 Mikayla Hutchinson [MSFT] 2013-01-25 12:03:24 UTC
Actually, demoting to IList is fine IMO.

The issue I had was that it tried to demote to *object*, which would break the code.

However, I can no longer reproduce that issue.
Comment 3 Mikayla Hutchinson [MSFT] 2013-01-25 12:04:15 UTC
Ah, IList<T> is okay. IList is not. So your fix is still good :)
Comment 4 Mikayla Hutchinson [MSFT] 2013-01-25 12:14:20 UTC
Hm, or maybe not. Technically IList is okay here too.
Comment 5 Mike Krüger 2013-01-26 00:08:39 UTC
it makes no real sense to 'forbid' arrays - I don't think that we should advise using ILists instead.
Comment 6 Mikayla Hutchinson [MSFT] 2013-01-26 16:52:53 UTC
Well, the point of demoting the parameter to IList is so that consumers can pass in other IList implementations, e.g. an ArrayList. As long as it's valid, i.e. everything you do to the parameter can be done on an IList, this demotion is a reasonable suggestion IMO, as it makes the API more flexible for consumers.
Comment 7 Mike Krüger 2013-01-28 01:18:14 UTC
It's not about API flexibility in this case. When I use arrays then I've a reason to do it - from my POV I use arrays when I want speed.

Now when changing them to ILists I loose some optimizations that can be done with arrays. Arrays are not really ILists - even if they implement that interface.
Comment 8 Mike Krüger 2013-08-20 06:51:36 UTC
Ok I changed it back to IList (or IList<T> for non objects).

We generally suggest API flexibility & readable code in other cases - for consistency reasons I'll make it here too. 

If performance is a problem the user should just ignore this rule.