[Issue 17992] New: auto return type and null for classes
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 19 07:36:25 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17992
Issue ID: 17992
Summary: auto return type and null for classes
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: temtaime at gmail.com
class C
{
int v;
C parent;
C[] childs;
auto foo(int a)
{
a -= v;
if(parent && a < 0)
{
return null;
}
foreach(c; childs)
{
if(auto r = c.foo(a))
{
pragma(msg, typeof(r));
return r;
}
}
if(parent)
{
return this;
}
return null;
}
}
void main()
{
auto a = new C, b = new C;
a.v = 12;
b.parent = a;
a.childs ~= b;
assert(a.foo(123) is b);
}
It passes, but prints typeof(null)
It should print C or give an error with pragma or doesn't compile at all.
LDC team says it's impossible to generate code from frontend data so this
example doesn't work with ldc.
--
More information about the Digitalmars-d-bugs
mailing list