Permalink
Browse files

Fix exception in type substitution when accessing multidimensional ar…

…rays that have a type parameter as element type. Closes #43.
  • Loading branch information...
1 parent ef5ef62 commit 680d7a413e04b9c67272816fd904af4f59360ec4 @dgrunwald dgrunwald committed Feb 24, 2011
@@ -524,7 +524,11 @@ static TypeReference SubstituteTypeArgs(TypeReference type, MemberReference memb
if (gp.Owner.GenericParameterType == GenericParameterType.Method) {
return ((GenericInstanceMethod)member).GenericArguments[gp.Position];
} else {
- return ((GenericInstanceType)member.DeclaringType).GenericArguments[gp.Position];
+ if (member.DeclaringType is ArrayType) {
+ return ((ArrayType)member.DeclaringType).ElementType;
+ } else {
+ return ((GenericInstanceType)member.DeclaringType).GenericArguments[gp.Position];
+ }
}
}
return type;
@@ -50,6 +50,7 @@
<ItemGroup>
<Compile Include="DelegateConstruction.cs" />
<Compile Include="ExceptionHandling.cs" />
+ <Compile Include="MultidimensionalArray.cs" />
<Compile Include="Loops.cs" />
<Compile Include="PropertiesAndEvents.cs" />
<Compile Include="TestRunner.cs" />
@@ -0,0 +1,27 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
+
+using System;
+
+public static class MultidimensionalArray
+{
+ internal class Generic<T, S> where T : new()
+ {
+ private T[,] a = new T[20, 20];
+ private S[,][] b = new S[20, 20][];
+
+ public T this[int i, int j]
+ {
+ get { return a[i, j]; }
+ set { a[i, j] = value; }
+ }
+
+ public void TestB(S x, ref S y)
+ {
+ b[5, 3] = new S[10];
+ b[5, 3][0] = default(S);
+ b[5, 3][1] = x;
+ b[5, 3][2] = y;
+ }
+ }
+}

0 comments on commit 680d7a4

Please sign in to comment.