Monday, 15 July 2013

csc - Why does the C# compiler crash on this code? -



csc - Why does the C# compiler crash on this code? -

why code below crash .net compiler? tested on csc.exe version 4.0.

see e.g. here online demo on different version - crashes in same manner while says dynamic not supported https://dotnetfiddle.net/fmn59s:

compilation error (line 0, col 0): internal compiler error (0xc0000005 @ address xy): culprit 'transform'.

the extension method works fine on list<dynamic> though.

using system; using system.collections.generic; static class f { public static void m<t>(this ienumerable<t> enumeration, action<t> action){} static void u(c.k d) { d.m(kvp => console.writeline(kvp)); } } class c { public class k : dictionary<string, dynamic>{} }

update: doesn't crash compiler

static void u(dictionary<string, dynamic> d) { d.m(kvp => console.writeline(kvp)); }

update 2: same bug reported in http://connect.microsoft.com/visualstudio/feedback/details/892372/compiler-error-with-dynamic-dictinoaries. bug reported firstordefault, seems compiler crashes on extension method applied class derived dictionary<t1,t2>, @ to the lowest degree 1 of parameter types dynamic. see more general description of problem below erik funkenbusch.

update 3: non-standard behaviour. when seek phone call extension method static method, is, f.m(d, kvp => console.writeline(kvp));, compiler doesn't crash, cannot find overload: argument 1: cannot convert 'c.k' 'system.collections.generic.ienumerable<system.collections.generic.keyvaluepair<string,dynamic>>'

update 4 - solution (kind of): hans sketched 2nd workaround, semantically equivalent original code, works extension method phone call , not standard call. since bug caused fact compiler fails cast class derived generic class multiple parameters (with 1 beingness dynamic) supertype, solution provide explicit cast. see https://dotnetfiddle.net/onvlcl:

((dictionary<string, dynamic>)d).m(kvp => console.writeline(kvp)); m((dictionary<string, dynamic>)d, kvp => console.writeline(kvp));

it dynamic triggering instability, crash disappears when replace object.

which 1 workaround, other help infer right t:

static void u(c.k d) { d.m(new action<keyvaluepair<string, dynamic>>(kvp => console.writeline(kvp))); }

the feedback report found strong match, no need file own i'd say.

c# csc

No comments:

Post a Comment