Thread overview
cast question
Oct 31, 2012
Dan
Oct 31, 2012
Tobias Pankrath
Oct 31, 2012
Dan
Oct 31, 2012
Tobias Pankrath
October 31, 2012
Why do the commented out calls to goo fail?

Thanks
Dan

-------------------------------------
import std.stdio;
struct S {
}
void goo(const ref S s) {
  writeln(s);
}
struct T {
  S s;
  void foo(const ref T other) const {
    goo(s);
    // Error: function fdsaf.goo (ref const(S) s) is
    //        not callable using argument types (S)
    // goo(cast(S)s);
    // goo(cast()s);   // same error
    writeln(typeid(S), " ", typeid(s), " ",
            typeid(cast()s), " ", typeid(cast(S)s));

  }
}
void main() {
  T t;
  t.foo(t);
  const S s1;
  S s2;
  goo(s1);
  goo(s2);
  goo(cast(S) s2);
  // goo(cast(S) s1); Also fails
}

October 31, 2012
On Wednesday, 31 October 2012 at 16:59:14 UTC, Dan wrote:
> Why do the commented out calls to goo fail?
>
> Thanks
> Dan
>

Compiles fine with git-head.
October 31, 2012
On Wednesday, 31 October 2012 at 17:11:47 UTC, Tobias Pankrath wrote:
> On Wednesday, 31 October 2012 at 16:59:14 UTC, Dan wrote:
>> Why do the commented out calls to goo fail?
>>
>> Thanks
>> Dan
>>
>
> Compiles fine with git-head.

I did git clone: git clone https://github.com/D-Programming-Language/dmd.git
The top of history is:
-----
Commits in HEAD
1e720552 * origin/master origin/HEAD master
         | Author: Walter Bright <walter@walterbright.com>
         | Date:   Wed Oct 31 02:33:17 2012 -0700
-----
Then I built only dmd per instructions here http://xtzgzorex.wordpress.com/2011/07/31/d-building-dmd-and-phobos-on-linux/

dmd -v
DMD64 D Compiler v2.061

I assume that is all that is necessary. I ran this dmd on the code (with comments removed of course) and got the same error:

dmd  -g -w -property  /.../tmp/fdsaf.d
/.../tmp/fdsaf.d(11): Error: function fdsaf.goo (ref const(S) s) is not callable using argument types (S)
/.../tmp/fdsaf.d(12): Error: function fdsaf.goo (ref const(S) s) is not callable using argument types (S)
/.../tmp/fdsaf.d(26): Error: function fdsaf.goo (ref const(S) s) is not callable using argument types (S)

Any suggestions?

Thanks
Dan

October 31, 2012
Ah, okay. I just dumped it into a file and ran dmd before leaving the office.

This looks like a compiler bug to me. The struct should be implicitly convertable to const(S)