Issue 11986 - IFTI type deduction / implicit conversion does not work for null literal
Summary: IFTI type deduction / implicit conversion does not work for null literal
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-01-24 12:35 UTC by Andrej Mitrovic
Modified: 2024-11-11 18:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2014-01-24 12:35:52 UTC
-----
class C(T) { }

void foo(T)(C!T a, C!T b) { }

void main()
{
    C!int c;
    foo(c, null);
}
-----

test.d(10): Error: template test.foo cannot deduce function from argument types !()(C!int, typeof(null)), candidates are:
test.d(5):        test.foo(T)(C!T a, C!T b)

null should be implicitly convertible to C!T since it's a reference type. Note that the programmer can't simply introduce another templated type parameter since the parameter might end up being typed as typeof(null), which is problematic. For example:

-----
class C(T) { void bar() { } }

void foo(T, T2)(C!T a, T2 b) if (is(T2 : C!T))
{
    b.bar();  // Error: no property 'bar' for type 'typeof(null)'
}

void main()
{
    C!int c;
    foo(c, null);
}
-----

So I think the OP case is rejects-valid.
Comment 1 Nick Treleaven 2023-08-26 11:26:13 UTC
Still happens with recent git.
Comment 2 basile-z 2024-11-11 18:25:09 UTC
The bug is much more specific than suggested by the summary.

1. it is limited to classes because the following works

```
struct S(T){}

void v(T)(S!T* a, S!T* b) {}

void main()
{
    S!int* a;
    v(a,null);
}   
```

2. it limited to classes templates because the following works

```
class S{}

void v(T)(T a, T b) {}

void main()
{
    S a;
    v(a,null);
}  
```