[Mono-dev] CS0019 for value type != null
Marek Safar
marek.safar at seznam.cz
Tue Apr 8 14:26:52 EDT 2008
Hello,
>
> > > I've noticed that on a recent SVN build of mono, I get a CS0019
> error if
> > > I try to compare a value type against null. E.g.:
> > >
> > > DateTime dt;
> > > if (dt != null)
> > > Console.WriteLine(dt);
> > >
> > > As far as I can tell, this is the correct behavior, since a value type
> > > can't be null. I'm concerned, though, because this behavior seems to
> > > have been introduced recently in SVN, AND it looks like MS's compiler
> > > doesn't reject this statement (well, I haven't seen it accept it, but
> > > this is existing code which apparently compiles fine under Visual
> > > Studio).
> > >
> > This code compiles correctly with the SVN HEAD version.
> >
>
> If I'm understanding correctly, then the SVN snapshot I have (a month
> old or so) is incorrect?
>
> I'll just update if that's the case.
>
Yes, the bug was fixed recently.
> > >
> > > So, my question is, what's going on here? Does anyone know what the
> > > semantics are if the compiler generates a conditional based on a
> > > `valuetype CMP null' test?
> > >
> > This particular comparison is in-lined to false constant.
> >
>
> Huh. Seems like an awfully bad way to handle that: if you aren't paying
> attention, some subtle bugs would creep in to code assuming that '==
> null' means something is uninitialized.
>
I am sorry but I did get this at all.
Regards,
Marek
More information about the Mono-devel-list
mailing list