[Mono-bugs] [Bug 437338] New: HasValue is true on a nullable field which gets null assigned
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue Oct 21 10:25:08 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=437338
Summary: HasValue is true on a nullable field which gets null
assigned
Product: Mono: Runtime
Version: 2.0
Platform: x86-64
OS/Version: Linux
Status: NEW
Severity: Normal
Priority: P5 - None
Component: JIT
AssignedTo: lupus at novell.com
ReportedBy: singer at conemis.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Created an attachment (id=246886)
--> (https://bugzilla.novell.com/attachment.cgi?id=246886)
the same code i posted in the description
The following code does some constructor chaining. In one of the chained
constructors the value null is passed to a nullable which is stored in a public
field of the created instance. If you call the HasValue property of this
nullable it should return false. But it returns true on x86_64 if you create
more than one instance of this type.
(g)mcs emits the same IL code on 32 and 64 bit, so i guess the problem is in
the jit.
Here is the code (sorry i did not get it smaller):
using System;
public struct ValTyp
{
public static readonly ValTyp Empty = new ValTyp(Guid.Empty, 0, 0);
public Guid g;
public int i1;
public int i2;
public ValTyp(Guid g, int i1, int i2)
{
this.g = g;
this.i1 = i1;
this.i2 = i2;
}
}
public abstract class Foo
{
public ValTyp? nvt;
protected Foo(ValTyp vt, ValTyp? nvt)
{
this.nvt = nvt;
Console.WriteLine("in Foo's ctor: nvt.HasValue==" +
nvt.HasValue.ToString());
}
}
public class Moo : Foo
{
public Moo(ValTyp vt, int i) :
base(vt, null) { } // <-- nvt is set to null here
public Moo(ValTyp vt) : this(vt, 0) { }
}
public static class Bar
{
public static void Main()
{
Moo moo = new Moo(ValTyp.Empty);
Console.WriteLine("in Main(1): moo.nvt.HasValue==" +
moo.nvt.HasValue.ToString());
moo = new Moo(ValTyp.Empty);
Console.WriteLine("in Main(2): moo.nvt.HasValue==" +
moo.nvt.HasValue.ToString());
if(moo.nvt.HasValue)
Console.WriteLine("HURRAY! It's Magic!");
}
}
On x86_64 this code outputs:
in Foo's ctor: nvt.HasValue==False
in Main(1): moo.nvt.HasValue==False
in Foo's ctor: nvt.HasValue==True
in Main(2): moo.nvt.HasValue==True
HURRAY! It's Magic!
And on x86, sparc and arm (all three are 32 bit) it outputs (as expected):
in Foo's ctor: nvt.HasValue==False
in Main(1): moo.nvt.HasValue==False
in Foo's ctor: nvt.HasValue==False
in Main(2): moo.nvt.HasValue==False
I tested it on Mono 1.9, 1.9.1 and 2.0. All three the same on x86_64.
Unfortunately i do not have another 64 bit architecture to test it.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list