[Mono-list] I think that this is a bug.

Daniel Carrera dcarrera@math.toronto.edu
Sun, 31 Mar 2002 02:54:46 -0500 (EST)


I found a very strange behaviour in Mono.  When I make a class containing
a string variable, I can concatenate that string fine.  However, when the
class *also* has a double variable, the concatenation fails.

Consider the following code:

------------------------------------------------
 1 class Money {
 2	private double Amount;
 3	private string Currency;
 4
 5	//public Money(double amount,string currency) {
 6	public Money(string currency) {
 7		//Amount   = amount;
 8		Currency = currency;
 9	}
10	public string getCurrency() {
11		return Currency;
12	}
13 }
14
15 class TestMoney {
16
17	public static void Main() {
18		//Money m = new Money(200,"CAD");
19		Money m = new Money("CAD");
20		System.Console.WriteLine("Currency:  " + m.getCurrency());
21	}
22 }
------------------------------------

This runs fine.  However, the following does not:

------------------------------------
 1 class Money {
 2	private double Amount;
 3	private string Currency;
 4
 5	public Money(double amount,string currency) {
 6	//public Money(string currency) {
 7		Amount   = amount;
 8		Currency = currency;
 9	}
10	public string getCurrency() {
11		return Currency;
12	}
13 }
14
15 class TestMoney {
16
17	public static void Main() {
18		Money m = new Money(200,"CAD");
19		//Money m = new Money("CAD");
20		System.Console.WriteLine("Currency:  " + m.getCurrency());
21	}
22 }
------------------------------------

Notice, what I've done is I've commented lines 6 and 19 and I've
uncommented 5, 7 and 18.

Now I get the error:

prompt$ mono ConcatTest.exe

(process:6309): ** WARNING **: unhandled exception
System.OverflowException: "Number overflow"
in System.String:.ctor ()
in System.String:Concat ()
in .TestMoney:Main ()



The same error occurs if "Ammount" is a float instead of a double.
The error *does not* occur if "Ammount" is an int.


I hope that someone can make sense out of this.

Daniel.