Hi,

while writing a simple script parser and runtime engine, I coped with a
compiler exception. The exception was caused by the duplicate case int
the switch statement.
That is quite strange and related to that peace of specific code,
because I tried to reproduce the same with other code but with no effect
(the compiler correctly signals an error and doesn't crash).
So I attached the faulty peace of code (a snippet from my whole project).
Sadly , Monodevelop 0.18 doesn't report any error into the Error List !!
while in Build Output the exception output was shown: I had hard time
figuring out my code was faulty !

That's the Monodevelop Build Output:

Building Project: test (Debug)
Performing main compilation...
Exception caught by the compiler while compiling:
   Block that caused the problem begin at:
/home/#########/test/Main.cs(34,29):
                     Block being compiled:
[/home/#########/test/Main.cs(54,33):,Internal(1,1):]
System.NullReferenceException: Object reference not set to an instance
of an object
Internal compiler error at /home/#########/test/Main.cs(34,29)::
exception caught while emitting MethodBuilder [MainClass::Parse]


Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
  at Mono.CSharp.EnumMember.get_Value () [0x00000]
  at Mono.CSharp.Enum.GetDefinition (System.Object value) [0x00000]
  at Mono.CSharp.TypeManager.CSharpEnumValue (System.Type t,
System.Object value) [0x00000]
  at Mono.CSharp.SwitchLabel.Erorr_AlreadyOccurs (System.Type
switch_type, Mono.CSharp.SwitchLabel collision_with) [0x00000]
  at Mono.CSharp.Switch.CheckSwitch (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Switch.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.While.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
  at Mono.CSharp.EmitContext.ResolveTopBlock (Mono.CSharp.EmitContext
anonymous_method_host, Mono.CSharp.ToplevelBlock block,
Mono.CSharp.Parameters ip, IMethodData md, System.Boolean& unreachable)
[0x00000]


Build complete -- 0 errors, 0 warnings

---------------------- Done ----------------------

Build successful.


Mono version is:
[EMAIL PROTECTED]:~> mono --version
Mono JIT compiler version 1.2.6 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  x86
        Disabled:      none

System is :

[EMAIL PROTECTED]:~> uname -a
Linux openSUSE-Dev 2.6.22.17-0.1-default #1 SMP 2008/02/10 20:01:04 UTC
i686 athlon i386 GNU/Linux

Hope this could help.

Nicola

---
http://www.ndatech.it



// Main.cs created with MonoDevelop
// User: ndellamico at 7:29 PM 2/20/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;

namespace test
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");
		}
		private enum COMMANDS{
			GVAR,
			LVAR,
			EVT_ADD,
			EVT_DEL,
			SET,
			ADD,
			SUB,
			MUL,
			DIV,
			JE,
			JGE,
			JG,
			JLE,
			JL,
			GOTO,
			GOSUB,
		};
		public bool Parse( System.IO.StreamReader stream){
			int source_line_index= 0;
			while( stream.Peek()>= 0) {
				++source_line_index;
				string line= stream.ReadLine( ).Trim().ToUpper();
				// Check for empty line
				if( line.Length== 0)
					continue;
				// Check for comments
				if( line[0]== ';')
					continue;
				// Strip away comments
				string[] cmd_line= line.Split( ';');
				// Tokenize the command string
				string[] tokens= cmd_line[0].Split( new char[]{' ','\t'});

				// Other specific stuff here 
				// ... omitted for clarity
				
				// Command found
				COMMANDS cmd= (COMMANDS) System.Enum.Parse( typeof( COMMANDS), tokens[0]);
				switch( cmd) {			
					case COMMANDS.ADD:
						// Dummy stuff here
						System.Console.WriteLine( "command is ADD");
						break;
					case COMMANDS.MUL:
						// Dummy stuff here
						System.Console.WriteLine( "command is MUL");
						break;
					// This should cause a compiler exception error !! 
					case COMMANDS.MUL:
						System.Console.WriteLine( "command is MUL ");
						break;
				}
			}
		}
	}
}
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to