# HG changeset patch # User Christian Kamm # Date 1239545882 -7200 # Node ID d51b5fa41657370c593f622e01c489bf732024a9 # Parent 7c7072437a89135543a01b3b15f6bd141338f474 Implement static array -> static array cast. Fixes #223. dynamic array -> static array is still misssing! diff -r 7c7072437a89 -r d51b5fa41657 gen/arrays.cpp --- a/gen/arrays.cpp Sun Apr 12 14:58:18 2009 +0200 +++ b/gen/arrays.cpp Sun Apr 12 16:18:02 2009 +0200 @@ -939,7 +939,26 @@ else if (totype->ty == Tsarray) { if (Logger::enabled()) Logger::cout() << "to sarray" << '\n'; - assert(0); + + if (fromtype->ty == Tsarray) { + LLValue* uval = u->getRVal(); + + if (Logger::enabled()) + Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; + + assert(isaPointer(uval->getType())); + const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); + + if(arrty->getNumElements()*fromtype->nextOf()->size() % totype->nextOf()->size() != 0) + { + error(loc, "invalid cast from '%s' to '%s', the element sizes don't line up", fromtype->toChars(), totype->toChars()); + fatal(); + } + + rval = DtoBitCast(uval, getPtrToType(tolltype)); + } + else + assert(0 && "Cast to static array not implemented!"); } else if (totype->ty == Tbool) { // return (arr.ptr !is null)