D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5416 - null should have a type of its own
Summary: null should have a type of its own
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2011-01-05 16:30 UTC by Simen Kjaeraas
Modified: 2011-11-25 00:29 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Simen Kjaeraas 2011-01-05 16:30:53 UTC
Currently, it is impossible to special-case comparisons with null. If instead null had its own type, one could allow direct comparisons between user-defined types and null, instead of supporting comparison with any and all void*s.

For structs, such a comparison function could then be used for both 'foo == null' and 'foo is null'. For classes, neither likely makes sense.
Comment 1 Benjamin Thaut 2011-10-07 09:08:52 UTC
Also if you pass null to a template it completely looses its implict conversion abilites. See following example.

void foo(Object o){
}

void fooHelper(T)(T o){
  foo(o);
}

void main(string[] args){
  fooHelper(null); //can not implicitly convert void* to Object
}

This also stops std.conv.emplace to work correctly with constructors you want to pass null to.
Comment 3 timon.gehr 2011-10-27 02:07:54 UTC
(In reply to comment #1)
> Also if you pass null to a template it completely looses its implict conversion
> abilites. See following example.
> 
> void foo(Object o){
> }
> 
> void fooHelper(T)(T o){
>   foo(o);
> }
> 
> void main(string[] args){
>   fooHelper(null); //can not implicitly convert void* to Object
> }
> 
> This also stops std.conv.emplace to work correctly with constructors you want
> to pass null to.

This is still true if 'Object' is replaced by Object[], 'null' is replaced by '[]' and 'void*' by 'void[]'. Therefore, '[]' needs an own type too.

(I think it is the same issue, or should I file a separate bug for it?)