Skip to content

Commit

Permalink
Fix exception in type substitution when accessing multidimensional ar…
Browse files Browse the repository at this point in the history
…rays that have a type parameter as element type. Closes #43.
  • Loading branch information
dgrunwald committed Feb 24, 2011
1 parent ef5ef62 commit 680d7a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
27 changes: 27 additions & 0 deletions ICSharpCode.Decompiler/Tests/MultidimensionalArray.cs
Original file line number Diff line number Diff line change
@@ -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.