Jump to page: 1 2
Thread overview
incompatible types!
Apr 05, 2011
Caligo
Apr 05, 2011
Caligo
Apr 05, 2011
Philippe Sigaud
Apr 05, 2011
Caligo
Apr 05, 2011
Caligo
Apr 06, 2011
Jonathan M Davis
Apr 06, 2011
simendsjo
April 05, 2011
import std.conv : to;

struct Matrix(T, size_t r, size_t c){

public:
  T[r*c] _data;

  Matrix opBinary(string op)(T scalar) if(op == "*"){
    string construct(){
      string result = "[";
      for(size_t i = 0; i < r * c; i++)
	result ~= "_data["~to!string(i)~"] * scalar, ";
      return result ~= "]";
    }
    return Matrix(mixin(construct()));
  }

  Matrix opBinary(string op)(ref const(Matrix) m)
    const if(op == "+" || op == "-"){
    string construct(){
      string result = "[";
      for(size_t i = 0; i < r * c; i++)
	result ~= "_data["~to!string(i)~"]"~op~"m._data["~to!string(i)~"], ";
      return result ~= "]";
    }
    return Matrix(mixin(construct()));
  }
}

struct A(T){

public:
  Matrix!(T, 3, 1) _a;
  alias _a this;

  this(T a, T b, T c){
    this._data[0] = a;
    this._data[1] = b;
    this._data[2] = c;
  }
}


void main(){

  auto a = A!double(3, 3, 3);

  auto r1 = a * 3.0;  // ok
  auto r2 = a + a;   // ok
  auto r3 = a + (a * 3.0);  // Error: incompatible types for ((a) +
(a._a.opBinary(3.0e+0))): 'A!(double)' and 'Matrix!(double,3,1)'
}


Why does the last expression fail? and how do I fix it?
April 05, 2011
On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor@gmail.com> wrote:

> Why does the last expression fail? and how do I fix it?

Because alias this is not very well implemented yet (I've run into similar issues), and you fix it by creating a bug report or voting for an already existing one.

Sorry.

-Steve
April 05, 2011
On Tue, Apr 5, 2011 at 12:32 PM, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor@gmail.com> wrote:
>
>> Why does the last expression fail? and how do I fix it?
>
> Because alias this is not very well implemented yet (I've run into similar issues), and you fix it by creating a bug report or voting for an already existing one.
>
> Sorry.
>
> -Steve
>


*sigh*
April 05, 2011
On Tue, 05 Apr 2011 14:08:42 -0400, Caligo <iteronvexor@gmail.com> wrote:

> On Tue, Apr 5, 2011 at 12:32 PM, Steven Schveighoffer
> <schveiguy@yahoo.com> wrote:
>> On Tue, 05 Apr 2011 13:23:04 -0400, Caligo <iteronvexor@gmail.com> wrote:
>>
>>> Why does the last expression fail? and how do I fix it?
>>
>> Because alias this is not very well implemented yet (I've run into similar
>> issues), and you fix it by creating a bug report or voting for an already
>> existing one.
>>
>> Sorry.
>>
>> -Steve
>>
>
>
> *sigh*

Yeah, I know.  I'd stay away from alias this for now if you don't want to be disappointed :(

-Steve
April 05, 2011
What's strange is that

auto r3 = r1 + r2;

works. Bug indeed...
April 05, 2011
I searched the bugzilla and there are 'alias this' related bugs.  Some of them are 2 years old and have not been fixed.

I've heard bugs get fixed rather quickly if something is posted on reddit about them.
April 05, 2011
On Tue, 05 Apr 2011 15:48:36 -0400, Caligo <iteronvexor@gmail.com> wrote:

> I searched the bugzilla and there are 'alias this' related bugs.  Some
> of them are 2 years old and have not been fixed.

There are many bugs in that category.  inout I think is a prime example.

I don't really know what to say to appease your expectations, except to have patience or try learning the comipler code.  If I had time and was compiler-savvy I might fix some bugs, but I don't and I'm not.  Walter and Don seem to do a lot of good bug fixes, and usually these are critical issues.  I think it won't be long before Walter or Don can start working on half-implemented features.  I know of no timeline though.

>
> I've heard bugs get fixed rather quickly if something is posted on
> reddit about them.

I wouldn't push this avenue too much, if it is true, it's likely to become not true quite quickly if abused.

I think it's more that bugs posted on reddit from people outside the D community look like outward-facing warts, and Walter and Andrei have a compulsive urge to make sure those are covered up quickly.  I personally don't see why it's important, as long as progress is being made on *something*.  Clearly the most visible wart was lack of 64-bit support, and that is almost resolved.

But progress *is* being made.  I think that's what's important right now.  D2 is still very much beta, and Phobos 2 is very much alpha.

-Steve
April 05, 2011
It's just frustrating, that's all.  Writing thousands of lines of code and having everything stop because of a compiler bug is just frustrating.

I know progress is being made, and all that is appreciated.  But, I don't remember ever hearing anything about D2 being in beta.  If anything, I remember months ago where D2 was recommended for new projects.  So, now I'm not sure what I'm supposed to do.  Start all over again from scratch?  I really like my design, so I guess I'll have to wait till it gets fixed.
April 06, 2011
On Tue, 05 Apr 2011 19:37:15 -0400, Caligo <iteronvexor@gmail.com> wrote:

> It's just frustrating, that's all.  Writing thousands of lines of code
> and having everything stop because of a compiler bug is just
> frustrating.

I completely understand.  It's why I have to periodically stop using D.  Dcollections sat idle for over a year while I waited for a compiler bug to be fixed.

> I know progress is being made, and all that is appreciated.  But, I
> don't remember ever hearing anything about D2 being in beta.  If
> anything, I remember months ago where D2 was recommended for new
> projects.  So, now I'm not sure what I'm supposed to do.  Start all
> over again from scratch?  I really like my design, so I guess I'll
> have to wait till it gets fixed.

Sorry you got that impression.  The fact is, as long as you are using the non-broken features, D2 is pretty useful, even downright awesome :)  The issue is, if you hit one of those broken ones.  Unfortunately, the release of TDPL didn't make all those features magically appear fully implemented.  So since TDPL is promoted as the offical language spec, D2 suddenly jumped way back in the release cycle, since many of its unimplemented/not-fully-implemented features became "official".

I'd highly recommend *NOT* to use D2 for new projects unless you are willing to redesign your code to work around those issues, or wait for them to be fixed.  I truly wish this wasn't the case, but I don't see how anyone can confidently recommend D2 for professional or non-toy projects.  This may sound like an anti-endorsement, but I assure you it is not.  I think D2 is going to be absolutely killer when it's finished.  I just would not use it for professional development *right now*, where deadlines and budgets are under consideration.  If you can afford to put it down when it breaks and wait for a fix, then I think it will be worth the wait.

-Steve
April 06, 2011
> On Tue, 05 Apr 2011 19:37:15 -0400, Caligo <iteronvexor@gmail.com> wrote:
> > It's just frustrating, that's all.  Writing thousands of lines of code and having everything stop because of a compiler bug is just frustrating.
> 
> I completely understand.  It's why I have to periodically stop using D. Dcollections sat idle for over a year while I waited for a compiler bug to be fixed.
> 
> > I know progress is being made, and all that is appreciated.  But, I don't remember ever hearing anything about D2 being in beta.  If anything, I remember months ago where D2 was recommended for new projects.  So, now I'm not sure what I'm supposed to do.  Start all over again from scratch?  I really like my design, so I guess I'll have to wait till it gets fixed.
> 
> Sorry you got that impression.  The fact is, as long as you are using the non-broken features, D2 is pretty useful, even downright awesome :)  The issue is, if you hit one of those broken ones.  Unfortunately, the release of TDPL didn't make all those features magically appear fully implemented.  So since TDPL is promoted as the offical language spec, D2 suddenly jumped way back in the release cycle, since many of its unimplemented/not-fully-implemented features became "official".
> 
> I'd highly recommend *NOT* to use D2 for new projects unless you are willing to redesign your code to work around those issues, or wait for them to be fixed.  I truly wish this wasn't the case, but I don't see how anyone can confidently recommend D2 for professional or non-toy projects. This may sound like an anti-endorsement, but I assure you it is not.  I think D2 is going to be absolutely killer when it's finished.  I just would not use it for professional development *right now*, where deadlines and budgets are under consideration.  If you can afford to put it down when it breaks and wait for a fix, then I think it will be worth the wait.

IIRC, Adam Ruppe uses D2 for professional development, and he discusses it from time to time on the main d newsgroup, but he specifically avoids some of the newer features. He rarely runs into problems with compiler.

On the other hand, folks who consistently try and use the newer features in their code - especially when they try and mix them - run into problems all too frequently. I ran into a number of major issues while creating std.datetime. A number of them have been fixed now. Others remain unfixed and still affect affect std.datetime to some degree (e.g. it's impossible to create an immutable SysTime). But std.datetime uses some of the newer features quite heavily (though alias this isn't one of them).

So, if you restrict what you do with D2 to an older subset of the language, you're likely to be fine. But if you try and use a lot of the newer features, you _will_ run into bugs. And alias this is definitely one of the areas with problems.

Personally, I only use D2 for my personal stuff, but as much as I'd like to use it at work, I wouldn't even attempt to yet. The language is stabilizing, and the compiler and libraries are definitely improving, but if you expect rock-solid stability, you're going to be dissapointed. We're getting there, but we're not there yet.

- Jonathan M Davis
« First   ‹ Prev
1 2