Bug 7808 – Nullable's alias this does not work with structs containing classes
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-01T22:18:00Z
Last change time
2015-06-09T05:15:01Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2012-04-01T22:18:58Z
This code compiled just fine with 2.058
import std.typecons;
void main()
{
auto s = Nullable!S(S(new C));
func(s);
}
class C
{
}
struct S
{
C c;
this(C c)
{
this.c = c;
}
}
void func(S s)
{
}
But it fails to compile with the latest dmd, giving the error
q.d(6): Error: function q.func (S s) is not callable using argument types (Nullable!(S))
q.d(6): Error: cannot implicitly convert expression (s) of type Nullable!(S) to S
It works if the member variable is an int or string. It works if the member variable is a struct type which does _not_ have a class as a member variable. But if the struct has a member variable which is a class, or it has a member variable which is a struct which has a member variable which is a class, then it fails.
Nullable!S' alias this should convert it to an S when passed to func, but it doesn't when S contains a member variable which is a class - either directly or indirectly.