Bugzilla – Bug 320565
[ANONYMOUS METHODS] (FIXED) CS1629: Iterator implementation in unsafe class fails to compile
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by horst.reiterer@mind-breeze.com 2006-03-16 15:52:07 MST ---- The following testcase fails to compile with Mono 1.1.13's gmcs (/d:FAILURE). The testcase defines an unsafe class with an iterator implementation which calls a method containing unsafe code. If only the method itself is marked as unsafe, compilation succeeds. In Microsoft's csc case, compilation succeeds in both cases. using System; using System.Collections.Generic; #if FAILURE unsafe #endif class Test { public static void Main() { foreach (int item in GetItems()) { Console.WriteLine(item); } } public static unsafe int GetItem() { byte[] value = new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }; fixed (byte* valueptr = value) { return *(int*)valueptr; } } public static IEnumerable<int> GetItems() { yield return GetItem(); } } Steps to reproduce the problem: 1. gmcs /d:FAILURE testcase.cs Actual Results: testcase.cs(27,5): error CS1629: Unsafe code may not appear in iterators Compilation failed: 1 error(s), 0 warnings Expected Results: Successful compilation with /d:FAILURE How often does this happen? 100 out of 100 times ---- Additional Comments From marek.safar@seznam.cz 2006-03-16 18:13:14 MST ---- I think my IResolveContext refactoring fixed this issue for mcs. But this is not yet part of gmcs. ---- Additional Comments From martin@ximian.com 2006-10-04 18:19:17 MST ---- Fixed in SVN. Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Red Hat Enterprise Linux 4</cf_op_sys_details> Unknown operating system other. Setting to default OS "Other".