[Mono-dev] About recursivily and setters / getters

Romain Tartière romain at blogreen.org
Sun Sep 6 15:30:05 EDT 2009


After reforactoring some code in a Test Driven Developed project, I got
myself stuck with NUnit crashing when testing the code.

After commenting out large portions of tests and then uncommenting until
them the crash occurred, I found my error.  I had a typo in a setter,
basically 'int X { set { X = value; } }'.

What bugged me is the error: I did not have any warning when compiling,
and it was just crashing after running a random number of unit tests
(but often 0) with the message:
| illegal hardware instruction (core dumped)

... and the return code from the process corresponds to a process killed
by the SIGILL signal.

At first, I though that using the property from it setter / getter was
invalid, but it does not produce an error nor warning. Moreover, I can
imagine that under some circumstances, one would need to do some
recursion and it should by syntactically correct.  So in my case, my
code should have run in an infinite loop... but the crash was almost

So I created a sample program with a property getting it's value
recursively to see what happens, I had exactly the same crash.  Awful
example follow (can't find some "smart" example, so I just submit an
ugly test case):

using System;

class Foo
	public static void Main()
		Foo f = new Foo();
		f.Even = 11;

	public int Even {
		get {
			if (x % 2 == 0)
				return x;
				return Even - 1;
		set { x = value; }

	private int x = 0;

I guess this crash is somewhat violent.  Should a bug be opened for
this? Any comment?

This is with mono


Romain Tartière <romain at blogreen.org>        http://romain.blogreen.org/
pgp: 8DAB A124 0DA4 7024 F82A  E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43)
(plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090906/bdca259b/attachment.bin 

More information about the Mono-devel-list mailing list