[nem-bug] [Nemerle 0000719]: NotNull doesn't work with generic
function parameters
feedback at nemerle.org
feedback at nemerle.org
Fri Jul 14 14:24:45 CEST 2006
A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=719>
======================================================================
Reported By: aleksey
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 719
Category: The Macro Library
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 07-14-2006 06:36 CEST
Last Modified: 07-14-2006 14:24 CEST
======================================================================
Summary: NotNull doesn't work with generic function
parameters
Description:
Example:
def foo[T]([NotNull] bar : T) : void
{
// some code
}
Error message:
error: comparing a value type T.722 to System.Object (a `null' literal?)
with reference equality
Minimal example without NotNull macro:
def foo[T](bar : T) : bool
{
bar != null
// the only workaround which seems to work
// (bar : object) != null
}
C# example which works:
static class Foobar
{
static bool Foo<T>(T bar)
{
return bar != null;
}
static void Main()
{
System.Console.WriteLine(Foo(20));
}
}
======================================================================
----------------------------------------------------------------------
nazgul - 07-14-06 12:33
----------------------------------------------------------------------
I don't think we should allow comparison to null for values, which may be
value types. If you added ': class' contraint, it should then work.
----------------------------------------------------------------------
aleksey - 07-14-06 14:19
----------------------------------------------------------------------
I see, though not exactly understand why(e.g. why C# designers allowed it
then). But in fact my report relates more to NotNull macro, rather than
comparison to null.
Imagine that we have some sort of method which *must* accept both
reference and value type parameters. For reference types it would be handy
to check for null. Adding ': class' constraint is not a solution at all,
since there is need to support both reference and value types. I wouldn't
care for comparison to null if NotNull worked in such cases, since NotNull
is much more concise and readable.
----------------------------------------------------------------------
Snaury - 07-14-06 14:24
----------------------------------------------------------------------
> Imagine that we have some sort of method which *must* accept both
reference and value type parameters.
I believe that's exactly why C# designers allowed it. For value types it
just always returns true, but for reference types it might be handy.
Looking at il made by C# reveals that it boxes argument to T compares to
null and it just works...
Issue History
Date Modified Username Field Change
======================================================================
07-14-06 06:36 aleksey New Issue
07-14-06 12:33 nazgul Note Added: 0001367
07-14-06 14:19 aleksey Note Added: 0001368
07-14-06 14:24 Snaury Note Added: 0001369
======================================================================
More information about the bugs
mailing list