[Mono-bugs] [Bug 76333][Nor] New - Referencing method member as
prop/field in foreach dies
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Oct 4 20:35:16 EDT 2005
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by latexer at gentoo.org.
http://bugzilla.ximian.com/show_bug.cgi?id=76333
--- shadow/76333 2005-10-04 20:35:16.000000000 -0400
+++ shadow/76333.tmp.23147 2005-10-04 20:35:16.000000000 -0400
@@ -0,0 +1,66 @@
+Bug#: 76333
+Product: Mono: Compilers
+Version: 1.1
+OS:
+OS Details: Gentoo
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com
+ReportedBy: latexer at gentoo.org
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Referencing method member as prop/field in foreach dies
+
+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 at 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.
More information about the mono-bugs
mailing list