Bug 8904 - List<t>.Reverse fails in Mono 3.0.3 where T is a struct
Summary: List<t>.Reverse fails in Mono 3.0.3 where T is a struct
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-12 10:44 UTC by Dennis Kingsley
Modified: 2017-08-28 15:05 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
source code, project files, nuint assemblies and scripts to produce bug. (3.47 MB, application/x-zip-compressed)
2012-12-12 10:44 UTC, Dennis Kingsley
Details

Description Dennis Kingsley 2012-12-12 10:44:53 UTC
Created attachment 3083 [details]
source code, project files, nuint assemblies and scripts to produce bug.

I am porting our application to Mono 3.0.x which has been running on Mono 2.11.5 correctly for months and have come accross the subject issue.

If I create a List<T> of Struct obects in my case two distinct Point3DVal's and call Reverse() on the list, the list will correct reverse order on .Net under win7 with Visual Studio 2010.

List<Point3DVal> target = new List<Point3DVal>();

target.Add(new Point3DVal(1, 2, 3));
target.Add(new Point3DVal(4, 5, 6));

Console.WriteLine("Before Reverse target[0] = {0}", target[0]);
Console.WriteLine("Before Reverse target[1] = {0}", target[1]);

target.Reverse();

Console.WriteLine("After Reverse target[0] = {0}", target[0]);
Console.WriteLine("After Reverse target[1] = {0}", target[1]);

Correctly Yields:

Before Reverse target[0] = {1,2,3}
Before Reverse target[1] = {4,5,6}
After Reverse target[0] = {4,5,6}
After Reverse target[1] = {1,2,3}


Using Mono 3.0.3 (master/d7c9ef0 Mon Dec 10 09:26:11 EST 2012), compiled on a RHEL 5.4 system using Gcc44 I get very strange results.

Before Reverse target[0] = {1,2,3}
Before Reverse target[1] = {4,5,6}
After Reverse target[0] = {2,1,3}
After Reverse target[1] = {4,5,6}

Notice that the points in the list did not get reordered, but the x and y values of the first element did. The structure in use is immutable.

If I change the Reverse() to use the extention method I get the correct results on both .Net and Mono 3.0.3.

target = new List<Point3DVal>(target.Reverse<Point3DVal>());

I have attached a paired down project that contains the struct in a class library and a unit test project using NUnit. You can use the project file to build and run the unit tests in Visual Studio 2010. And I have provided bash script to build the project in Mono on Linux and one to run the unit tests.

Dennis Kingsley
Manager Hydrodynamics and High Performance Computing
DRS Defense Solutions, LLC
Advanced Marine Technology Center
160 Sallitt Drive, Suite 200
Stevensville, MD, 21666
Phone: 410-604-8010  
Fax: 410-643-5370
dkingsley@drs-ds.com
Comment 1 Zoltan Varga 2012-12-16 15:40:22 UTC
Fixed in master.
Comment 2 Dennis Kingsley 2012-12-17 08:20:31 UTC
Confirmed fix on target machine, thanks for the fast run around.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.