November 09, 2012
Is there a fundamental problem with this?
The second assert causes compile below. Without the postblit there is no error.

Thanks
Dan

Error: function postblit.S.__postblit () is not callable using argument types () const
//postblit.d(6): Error: template instance object.AssociativeArray!(string,const(S)) error instantiating

------------------------------------
struct S {
  this(this) {}
}

void main() {
  S[string] s1, s2;
  assert(s1==s2);

  S[S[string]] w1, w2;
  assert(w1==w2);
}

November 09, 2012
On Friday, 9 November 2012 at 13:15:15 UTC, Dan wrote:
> ...

Actually error message is:

Error: function hello.S.__postblit () is not callable using argument types ()
Error: *&this is not mutable
Error: this is not mutable
Error: this is not mutable
hello.d(6): Error: template instance object.AssociativeArray!(string,const(S)) error instantiating

Making postblit accept const this makes dmd happy.

Seems to be caused by S[S[string]] which requires "this" to be const.
November 09, 2012
On Friday, 9 November 2012 at 14:29:06 UTC, Maxim Fomin wrote:
> Error: function hello.S.__postblit () is not callable using argument types ()
> Error: *&this is not mutable
> Error: this is not mutable
> Error: this is not mutable
> hello.d(6): Error: template instance object.AssociativeArray!(string,const(S)) error instantiating
>
> Making postblit accept const this makes dmd happy.
>
> Seems to be caused by S[S[string]] which requires "this" to be const.

I'm using (DMD64 D Compiler v2.061) and don't see it, so it seems moving from v2.060 to v2.061 takes away some useful error messages which is bad.

I don't think making postblit accept const works - did it for you? If you just mean "this(const this)" it does make it compile - but that postblit is not called.

For example, in code below nothing is printed. Maybe there is a better signature - what did you use? Make postblit this(this) and it is printed. Back to the other example - it seems only this(this) is ever recognized and having this(this) is a problem with associative arrays.

Here is a related thread which in my mind is not resolved.

http://forum.dlang.org/thread/jonkbhtibdxjfjethtuo@forum.dlang.org#post-jonkbhtibdxjfjethtuo:40forum.dlang.org

Thanks
Dan

import std.stdio;
struct S {
  this(const this) { writeln("Is this called"); }
}

void main() {
  S x;
  const(S) cx;
  S x2 = x;
  S x3 = cx;
}
November 09, 2012
On Friday, 9 November 2012 at 16:24:31 UTC, Dan wrote:
> I'm using (DMD64 D Compiler v2.061) and don't see it, so it seems moving from v2.060 to v2.061 takes away some useful error messages which is bad.

Experimenting on dpaste site shows that error message was fixed in trunk (you can select compiler version there).

>
> I don't think making postblit accept const works - did it for you? If you just mean "this(const this)" it does make it compile - but that postblit is not called.
>

Making parameter to be const solves that problem.

> For example, in code below nothing is printed. Maybe there is a better signature - what did you use? Make postblit this(this) and it is printed. Back to the other example - it seems only this(this) is ever recognized and having this(this) is a problem with associative arrays.
>
> Here is a related thread which in my mind is not resolved.
>
> http://forum.dlang.org/thread/jonkbhtibdxjfjethtuo@forum.dlang.org#post-jonkbhtibdxjfjethtuo:40forum.dlang.org
>
> Thanks
> Dan
>
> import std.stdio;
> struct S {
>   this(const this) { writeln("Is this called"); }
> }
>
> void main() {
>   S x;
>   const(S) cx;
>   S x2 = x;
>   S x3 = cx;
> }

Look at this: http://dpaste.dzfl.pl/1f60055d. It is a combination of original code and code above. It fails to compile, but commenting this(this) makes dmd happy. Alternatively you can comment S[S[string]] w1, w2 and everything also works fine.

November 09, 2012
On Friday, 9 November 2012 at 17:27:18 UTC, Maxim Fomin wrote:

> Experimenting on dpaste site shows that error message was fixed in trunk (you can select compiler version there).
>

Excellent tool - I'll use it more. I'm using a version of the trunk from not long ago and the dmd version output from "dmd -v" is 2.061. dpaste does not provide 2.061 as an option. The difference in error messages is between 2.060 and 2.061 (i.e. if I use my 2.060 I see same message as you - more detailed==better).

>>
>> I don't think making postblit accept const works - did it for you? If you just mean "this(const this)" it does make it compile - but that postblit is not called.
>>
>
> Making parameter to be const solves that problem.

Not to me. Sorry if I'm missing something, but a solution would be that it not only compile, but it invoke my this(const this) postblit, which unless I'm missing something it does not.

>
> Look at this: http://dpaste.dzfl.pl/1f60055d. It is a combination of original code and code above. It fails to compile, but commenting this(this) makes dmd happy. Alternatively you can comment S[S[string]] w1, w2 and everything also works fine.

Look at this: http://dpaste.dzfl.pl/95d40612
I commented out this(this) and dmd is happy, but I am not because nothing is printed. This is quite bad because I think I'll be duping all my members but it won't get called and sharing will ensue. What am I missing?

Thanks,
Dan
November 09, 2012
On Friday, 9 November 2012 at 17:58:27 UTC, Dan wrote:
>>> I don't think making postblit accept const works - did it for you? If you just mean "this(const this)" it does make it compile - but that postblit is not called.
>>>
>>
>> Making parameter to be const solves that problem.
>
> Not to me. Sorry if I'm missing something, but a solution would be that it not only compile, but it invoke my this(const this) postblit, which unless I'm missing something it does not.
>

I understood that the problem is in non-compiling.

>> Look at this: http://dpaste.dzfl.pl/1f60055d. It is a combination of original code and code above. It fails to compile, but commenting this(this) makes dmd happy. Alternatively you can comment S[S[string]] w1, w2 and everything also works fine.
>
> Look at this: http://dpaste.dzfl.pl/95d40612
> I commented out this(this) and dmd is happy, but I am not because nothing is printed. This is quite bad because I think I'll be duping all my members but it won't get called and sharing will ensue. What am I missing?
>
> Thanks,
> Dan

Well actually this(const this) appears to be not a copy constructor at all - thanks to treating func(Type) {} as func(Type _param_0){} it is converted to a regular constructor which may take arbitrary arguments and is irrelevant here. So, basically the problem is in:

struct S {
  this(this) {  }
}

void main() {
  S[S[string]] w1,w2;
  assert(w1==w2); //template instance error instantiating
}

Top | Discussion index | About this forum | D home