[Issue 7210] opCall weird behavior in struct
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 8 10:35:53 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7210
Gašper Ažman <gasper.azman at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
CC| |gasper.azman at gmail.com
--- Comment #1 from Gašper Ažman <gasper.azman at gmail.com> 2012-05-08 10:37:12 PDT ---
This is more about opCall not working for structs whenever a constructor is
present. For instance, this works:
import std.stdio;
struct B {
int number;
string word;
static B opCall(int n) {
B b = {n, ""};
return b;
}
string opCall(string w)
{
word = w;
return word;
}
}
void main() {
auto b = B(3);
writeln(b("Hello World"));
}
but this doesn't:
import std.stdio;
struct A {
int number;
string word;
this(int n) {
number = n;
word = "";
}
string opCall(string w)
{
word = w;
return word;
}
}
int main() {
auto a = A(3);
writeln(a("Hello World"));
}
atom at kamichan $ dmd test.d
test.d(20): Error: constructor test.A.this (int n) is not callable using
argument types (string)
test.d(20): Error: cannot implicitly convert expression ("Hello World") of type
string to int
test.d(18): Error: function D main has no return statement, but is expected to
return a value of type int
atom at kamichan $ dmd
DMD64 D Compiler v2.059
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list