This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8904 - List<t>.Reverse fails in Mono 3.0.3 where T is a struct
: List<t>.Reverse fails in Mono 3.0.3 where T is a struct
Status: RESOLVED FIXED
Product: Runtime
Classification: Mono
Component: generics
: unspecified
: PC Linux
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-12-12 10:44 EST by Dennis Kingsley
Modified: 2012-12-17 08:20 EST (History)
4 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


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

Description Dennis Kingsley 2012-12-12 10:44:53 EST
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 EST
Fixed in master.
Comment 2 Dennis Kingsley 2012-12-17 08:20:31 EST
Confirmed fix on target machine, thanks for the fast run around.

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