Re: Segfault when casting array of Interface types

2014-09-16 Thread Klaus via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 03:05:57 UTC, Franz wrote: On Tuesday, 16 September 2014 at 03:03:16 UTC, Franz wrote: On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 06:27:59 UTC, Klaus wrote: On Tuesday, 16 September 2014 at 03:05:57 UTC, Franz wrote: On Tuesday, 16 September 2014 at 03:03:16 UTC, Franz wrote: On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: AFACIS there's nothing wrong with his use of casting. It's fine here, because `I` is a base type of `C` and `D`. If it weren't for the arrays, the cast wouldn't even be necessary. I think it's a bug. Correction: AFAIK casting

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 08:49:04 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: Whether the compiler should accept that or not is a different question. I guess it should, because if it doesn't, there wouldn't be an easy way to achieve a

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 06:27:59 UTC, Klaus wrote: is just a horrible way of shortcuting the static typing. You write this thinking that i has to be... and then you complain latter because the cast does not work. D is a strongly typed lang. in your example you use auto because your

Re: Segfault when casting array of Interface types

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 11:26:05 UTC, rcor wrote: On Tuesday, 16 September 2014 at 08:49:04 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 08:39:43 UTC, Marc Schütz wrote: Whether the compiler should accept that or not is a different question. I guess it should, because

Re: Segfault when casting array of Interface types

2014-09-16 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 14:13:48 UTC, Marc Schütz wrote: On Tuesday, 16 September 2014 at 11:26:05 UTC, rcor wrote: Is to! creating a new array of pointers while cast isn't? This isn't a performance critical section and it's not a huge array, so I ask mostly out of curiosity. Yes,

Segfault when casting array of Interface types

2014-09-15 Thread rcor via Digitalmars-d-learn
I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and I have an array of each. I'd like to combine these into one I[], but eventually I'd like to cast an element back to its original type. interface I {} class C : I {} class D : I

Re: Segfault when casting array of Interface types

2014-09-15 Thread Franz via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and I have an array of each. I'd like to combine these into one I[], but eventually I'd like to cast an element back to its

Re: Segfault when casting array of Interface types

2014-09-15 Thread Franz via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 03:03:16 UTC, Franz wrote: On Tuesday, 16 September 2014 at 02:21:42 UTC, rcor wrote: I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and I have an array of each. I'd like to combine these into one

Re: Segfault when casting array of Interface types

2014-09-15 Thread rcor via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 03:05:57 UTC, Franz wrote: Your issue comme from auto. i is a I[] I expected i to be an I[], but shouldn't a casting an element of an I[] to a C return either a C or null? It is if I do this: I[] i = [cast(I) new C, new D]; assert(cast(C) i[0]); // fine

Re: Segfault when casting array of Interface types

2014-09-15 Thread rcor via Digitalmars-d-learn
seemingly even weirder: I[] i0 = [new C, new C]; assert(cast(C) i0[0]); // fine C[] c = [new C, new C]; I[] i1 = cast(I[]) c; assert(cast(C) i1[0]); // fails It works when I create an I[] from a C[] literal, but not when I cast a previously declared C[] to an I[].

Re: Segfault when casting array of Interface types

2014-09-15 Thread Ali Çehreli via Digitalmars-d-learn
On 09/15/2014 07:21 PM, rcor wrote: I'm back for another round of is this a bug, or am I doing something stupid?. C and D implement interface I, and I have an array of each. I'd like to combine these into one I[], but eventually I'd like to cast an element back to its original type. interface