Bugzilla – Bug 319198
Referencing method member as prop/field in foreach dies
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by latexer@gentoo.org 2005-10-04 20:35:16 MST ---- Description of Problem: Accidentially referencing a member method as if it were a field or property inside a foreach declaration makes mcs freak. The following test case makes mcs freak out with a nasty error message on mono-1.1.9.1 here: <snip> using System; using System.Text.RegularExpressions; public class MainClass { public static void Main (string[] args) { Regex reg = new Regex (@"\w"); foreach (Match match in reg.Matches) { Console.WriteLine("Match: |{0}|", match); } } } </snip> Inside the foreach, "Matches" is attempted to be referenced as a field/property, when it really should be 'reg.Matches("some string")'. The same mistake outside of the foreach conditional does *not* cause this error. Here is the full error message: <snip> peter@stu ~/csharp/playground $ mcs foreach-fubar.cs Exception caught by the compiler while compiling: Block that caused the problem begin at: foreach-fubar.cs(7,21): Block being compiled: [Internal(1,1):,Internal(1,1):] System.NullReferenceException: Object reference not set to an instance of an object Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object in <0x000ec> Mono.CSharp.Foreach:Resolve (Mono.CSharp.EmitContext ec) in <0x001b6> Mono.CSharp.Block:Resolve (Mono.CSharp.EmitContext ec) in <0x001b6> Mono.CSharp.Block:Resolve (Mono.CSharp.EmitContext ec) in <0x00122> Mono.CSharp.EmitContext:ResolveTopBlock (Mono.CSharp.EmitContext anonymous_method_host, Mono.CSharp.ToplevelBlock block, Mono.CSharp.InternalParameters ip, IMethodData md, System.Boolean unreachable) </snip. Let me know if any further information is required. ---- Additional Comments From marek.safar@seznam.cz 2005-10-05 04:54:43 MST ---- *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO76287 *** Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Gentoo</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other". This bug was marked DUPLICATE in the database it was moved from. Changing resolution to "MOVED"