struct : implicit conversion for function call arguments

d coder dlang.coder at gmail.com
Tue Jan 1 09:26:12 PST 2013


Greetings

I observed that struct type function call arguments do not implicitly
convert even when I define a valid constructor for type conversion. So DMD
complains for line 15 in the code listed below saying:
test.d(15): Error: function test.fiz (Bar _bar) is not callable using
argument types (Foo)
test.d(15): Error: cannot implicitly convert expression (foo) of type Foo
to Bar

Is this a bug, or is it intended behavior? If it is a bug, can somebody
please point me to the issue number filed on Bugzilla so that I can track
it. I made some effort to search it myself but could find it on Bugzilla.

And if it is intended behavior, I guess it is because of some issues with
template function matching. But I find explicit casting while calling
functions a bit of a stretch.

Regards
- Puneet

struct Foo { }                 // 1
                               // 2
struct Bar {                   // 3
  this (Foo _foo) { }          // 4
  void opAssign(Foo _foo) { }  // 5
}                              // 6
                               // 7
void fiz(Bar _bar) { }         // 8
                               // 9
void main() {                  // 10
  Foo foo;                     // 11
  // implicit conversion works // 12
  Bar bar = foo;               // 13
  // But not here              // 14
  fiz(foo);                    // 15
}                              // 16
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130101/530f3a15/attachment.html>


More information about the Digitalmars-d mailing list