Bug 372412

Summary: gmcs don't emit readonly prefix for generic array access.
Product: [Mono] Mono: Compilers Reporter: Rodrigo Kumpera <rkumpera>
Component: C#Assignee: Mono Bugs <mono-bugs>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Rodrigo Kumpera 2008-03-19 16:14:06 UTC
When generics code need to do load the address of an array element of generic type it must emit a readonly prefix, otherwise a System.ArrayTypeMismatchException will be raised.


For example:

T[] t;
t[0].GetHashCode();

Must be compiled to:

ldc.i4.0 
readonly. 
ldelema !T
constrained. !T
callvirt instance int32 object::GetHashCode()


Right now gmcs don't emit the readonly. prefix. This applies to Array::Address magic methods as well.

See #372410 for a test case and the long explanation of why the readonly prefix is required.
Comment 1 Marek Safar 2010-04-29 10:45:44 UTC
Fixed in trunk. Is there easy test for this?