Bugzilla – Bug 319501
[GMCS] [PATCH] Ensure distinct MonoTypes on resolving a typespec in different contexts
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by jankit@novell.com 2005-11-11 07:14:23 MST ---- Description of Problem: When we resolve a given typespec in different contexts, we should obtain a distinct MonoType for each context, and any GenericParams contained in that MonoType should point to the correct context. This is necessary since the generic_param->owner field can be used non-trivially, i.e., not just for printing names. This gets exposed with monodis. test case: class X<T1> { public static void Xfoo () { X<T1>.Xfoo(); --> Single TypeSpec, (VAR !0) } } class Y<T2> { public static void Yfoo () { X<T2>.Xfoo(); --> Same TypeSpec (VAR !0) } } Compiled with csc (mcs emits duplicate TypeSpecs) and monodis'ed shows: .class private auto ansi beforefieldinit 'X`1'<T1> { ... .method public static void Xfoo () cil managed { ... IL_0001: call void class 'X`1'<!T1>::Xfoo() --> !T1 is correct in this context ... } ... } .class private auto ansi beforefieldinit 'Y`1'<T2> { ... .method public static void Yfoo () cil managed { ... IL_0001: call void class 'X`1'<!T1>::Xfoo() --> !T1 instead of !T2 ******* ... } ... } Attached are three test cases(including the one above) and a proposed patch. test1.cs: When the typespec is a GenericInst test2.cs: When the typespec is an array/szarray of GenericInst/VAR/MVAR test3.cs: When the typespec is a VAR/MVAR Also attached are the csc generated assemblies for the 3 test cases. Patch forged with Hari. ---- Additional Comments From jankit@novell.com 2005-11-11 07:20:12 MST ---- Created an attachment (id=168793) test_cases.tgz : Contains the test cases (.cs) and corresponding csc compiled assemblies ---- Additional Comments From jankit@novell.com 2005-11-11 07:22:11 MST ---- Created an attachment (id=168794) typespec.patch : Proposed patch ---- Additional Comments From rharinath@novell.com 2005-11-12 08:00:14 MST ---- I think there's a subtle bug in the last part of the patch, where the types cache of the container is updated. I think you should use container = type->...->owner; instead of the passed-in generic_context. Also, it may be cleaner if this part of the code happens where the MonoType is allocated. ---- Additional Comments From jankit@novell.com 2005-11-14 04:59:48 MST ---- 1. Changed the code to use type->..->owner. 2. this MonoType is being allocated in mono_type_create_from_typespec_full itself, so i guess the code is fine here. Attached is the updated patch. ---- Additional Comments From jankit@novell.com 2005-11-14 05:00:40 MST ---- Created an attachment (id=168795) typespec2.patch: Updated patch ---- Additional Comments From jankit@novell.com 2005-11-15 06:22:33 MST ---- Committed. (r53043) Imported an attachment (id=168793) Imported an attachment (id=168794) Imported an attachment (id=168795) Unknown operating system unknown. Setting to default OS "Other".