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 I[], but eventually I'd like to cast an element back to its original type.

interface I {}
class C : I {}
class D : I {}

void main() {
 C[] c = [new C, new C];
 D[] d = [new D, new D];
 auto i = cast(I[]) c ~ cast(I[]) d;
 assert(cast(C) i[0]); // segfault
}

casting each array to I[] is fine, but casting an element back to C segfaults (even if it weren't a C, it should just return null, right?)

look at what 's auto has created:

import std.stdio;

interface I {}
class C : I {}
class D : I {}

void main() {
  C[] c = [new C, new C];
  D[] d = [new D, new D];
  auto i = cast(I[]) c ~ cast(I[]) d;
  writeln(typeof(i).stringof);
}

Your issue comme from auto.

i is a I[]


Reply via email to