Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 780

Show
Ignore:
Timestamp:
12/05/10 08:27:04 (14 years ago)
Author:
walter
Message:

bugzilla 5214 Compiler crash with array of empty {}

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/declaration.c

    r754 r780  
    732732 
    733733    /* Pick up storage classes from context, but skip synchronized 
    734734     */ 
    735735    storage_class |= (sc->stc & ~STCsynchronized); 
    736736    if (storage_class & STCextern && init) 
    737737        error("extern symbols cannot have initializers"); 
    738738 
    739739    /* If auto type inference, do the inference 
    740740     */ 
    741741    int inferred = 0; 
    742742    if (!type) 
    743743    {   inuse++; 
    744744 
    745745        ArrayInitializer *ai = init->isArrayInitializer(); 
    746746        if (ai) 
    747747        {   Expression *e; 
    748748            if (ai->isAssociativeArray()) 
    749749                e = ai->toAssocArrayLiteral(); 
    750750            else 
    751751                e = init->toExpression(); 
     752            if (!e) 
     753            { 
     754                error("cannot infer type from initializer"); 
     755                e = new ErrorExp(); 
     756            } 
    752757            init = new ExpInitializer(e->loc, e); 
    753758            type = init->inferType(sc); 
    754759            if (type->ty == Tsarray) 
    755760                type = type->nextOf()->arrayOf(); 
    756761        } 
    757762        else 
    758763            type = init->inferType(sc); 
    759764 
    760765//printf("test2: %s, %s, %s\n", toChars(), type->toChars(), type->deco); 
    761766//      type = type->semantic(loc, sc); 
    762767 
    763768        inuse--; 
    764769        inferred = 1; 
    765770 
    766771        if (init->isArrayInitializer() && type->toBasetype()->ty == Tsarray) 
    767772        {   // Prefer array literals to give a T[] type rather than a T[dim] 
    768773            type = type->toBasetype()->nextOf()->arrayOf(); 
    769774        } 
    770775 
    771776        /* This is a kludge to support the existing syntax for RAII