Bug 11308 – Don't use Voldemort types for std.process output
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-20T13:02:00Z
Last change time
2014-04-18T10:48:59Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-10-20T13:02:41Z
-----
import std.process;
void main()
{
auto res = executeShell("dmd");
if (res.status) { }
if (res.output) { }
// ok, reuse variable
res = executeShell("rdmd");
if (res.status) { }
if (res.output) { }
// NG. Even though return types are the same
res = execute(["dmd"]);
}
-----
$ dmd test.d
> Error: cannot implicitly convert expression (execute(["dmd"], null, cast(Config)0, 4294967295u)) of type ProcessOutput to ProcessOutput
The voldemort situation makes reusing variables impossible, even though the same exact type is returned (the only difference being the template is instantiated differently).
As a reduced test-case:
-----
auto foo(T)()
{
struct S { int x; }
return S(1);
}
void main()
{
auto res = foo!int();
res = foo!int();
// NG: Error: cannot implicitly convert expression (foo()) of type S to S
res = foo!double();
}
-----
This is a borderline compiler bug. Kenji I've CC'ed you to see if this is something worth thinking about, could the compiler be smart enough to deduce that the two Voldemort types are really the same type?
But even so, using `auto` for these process functions makes it very hard to figure out what the return type of a function is. We might as well use a proper non-voldemort struct.