You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following D2 program only the Mfoo1 compiles:
import std.functional: memoize;
struct Foo1 {
int x;
static Foo1 opCall(int x_) {
Foo1 f;
f.x = x_;
return f;
}
}
struct Foo2 {
int x;
}
struct Foo3 {
int x;
this(int x_) {
this.x = x_;
}
}
void main() {
alias memoize!Foo1 Mfoo1;
alias memoize!Foo2 Mfoo2;
alias memoize!Foo3 Mfoo3;
}
DMD 2.055 gives errors like:
...\src\phobos\std\traits.d(128): Error: static assert "argument has no return type"
...\src\phobos\std\functional.d(713): instantiated from here: ReturnType!(Foo2)
test.d(21): instantiated from here: memoize!(Foo2)
...\src\phobos\std\traits.d(128): Error: static assert "argument has no return type"
...\src\phobos\std\functional.d(713): instantiated from here: ReturnType!(Foo3)
test.d(22): instantiated from here: memoize!(Foo3)
The static assert is in std.traits:
template ReturnType(/+@@@BUG4217@@@+/func...)
if (/+@@@BUG4333@@@+/staticLength!(func) == 1)
{
static if (is(FunctionTypeOf!(func) R == return))
alias R ReturnType;
else
static assert(0, "argument has no return type");
}
I think Mfoo2 and Mfoo3 too should compile. Writing Foo2(5) is like calling the function Foo2 with argument x = 5, and returning a struct Foo2 result. I think this is a place where telling apart structs and functions is an artificial distinction that is the opposite of useful.
See one use case:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=144333
The text was updated successfully, but these errors were encountered:
bearophile_hugs reported this on 2011-09-13T04:18:51Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=6662
CC List
Description
In the following D2 program only the Mfoo1 compiles: import std.functional: memoize; struct Foo1 { int x; static Foo1 opCall(int x_) { Foo1 f; f.x = x_; return f; } } struct Foo2 { int x; } struct Foo3 { int x; this(int x_) { this.x = x_; } } void main() { alias memoize!Foo1 Mfoo1; alias memoize!Foo2 Mfoo2; alias memoize!Foo3 Mfoo3; } DMD 2.055 gives errors like: ...\src\phobos\std\traits.d(128): Error: static assert "argument has no return type" ...\src\phobos\std\functional.d(713): instantiated from here: ReturnType!(Foo2) test.d(21): instantiated from here: memoize!(Foo2) ...\src\phobos\std\traits.d(128): Error: static assert "argument has no return type" ...\src\phobos\std\functional.d(713): instantiated from here: ReturnType!(Foo3) test.d(22): instantiated from here: memoize!(Foo3) The static assert is in std.traits: template ReturnType(/+@@@BUG4217@@@+/func...) if (/+@@@BUG4333@@@+/staticLength!(func) == 1) { static if (is(FunctionTypeOf!(func) R == return)) alias R ReturnType; else static assert(0, "argument has no return type"); } I think Mfoo2 and Mfoo3 too should compile. Writing Foo2(5) is like calling the function Foo2 with argument x = 5, and returning a struct Foo2 result. I think this is a place where telling apart structs and functions is an artificial distinction that is the opposite of useful. See one use case: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=144333The text was updated successfully, but these errors were encountered: