Repro:
struct A {
@property foo() { return 42; }
}
This is correct code, the fact that foo is a function is inferred from the presence of @property, and the return type is deduced automatically from the body. However, if a .di file is generated it'll have this code:
struct A {
@property foo();
}
which is incorrect D.
Solution: keep the bodies of functions with automatically inferred type in the .di file.
Comment #1 by temtaime — 2015-06-14T02:14:16Z
I think bodies are useless and compiler knows return type, so solution is append return type to the prototype.
Comment #2 by andrei — 2015-06-14T21:09:44Z
May be Voldemort.
Comment #3 by ketmar — 2015-06-15T08:51:19Z
for voldemorts compiler can put `auto` there. yet this will require running semantic stage, which has it's complications (semantic stage mutilates ASTs).
the other solution is to simply emit the body for functions without explicit return type specification. they are rare anyway.
Comment #4 by razvan.nitu1305 — 2018-03-12T14:42:22Z
This has been fixed. Running the .di generator on the original post results in the following .di file:
// D import file generated from 'test.d'
struct A
{
@property foo()
{
return 42;
}
}
which is correct D compilable code. Closing as fixed.