Bug 4253 – opCall() not called in initialized struct

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-05-30T09:27:00Z
Last change time
2011-06-21T07:03:25Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-05-30T09:27:07Z
This is a small C++ program that compiles: template<typename T> struct Foo { Foo(T x) {} template<typename U> void operator()(U y) {} }; int main() { Foo<int> foo(1); foo(1.5); } I think this is an equivalent D2 program: struct Foo(T) { this(T x) {} void opCall(U)(U y) {} } void main() { auto foo = Foo!int(1); foo(1.5); // line 7 } But DMD V. 2.046 prints: temp.d(7): Error: constructor temp.Foo!(int).Foo.this (int x) is not callable using argument types (double) temp.d(7): Error: cannot implicitly convert expression (1.5) of type double to int
Comment #1 by bearophile_hugs — 2010-05-30T09:29:40Z
A simpler test case: struct Foo { this(int x) {} void opCall(double y) {} } void main() { Foo foo = Foo(1); foo(1.5); }
Comment #2 by bearophile_hugs — 2011-03-08T09:53:48Z
See also bug 4053
Comment #3 by k.hara.pg — 2011-06-21T07:03:25Z
*** This issue has been marked as a duplicate of issue 6036 ***