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 ()
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)

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


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 GitHub or Developer Community 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 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.