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

Changeset 614

Show
Ignore:
Timestamp:
08/10/10 23:08:57 (14 years ago)
Author:
walter
Message:

fix for inner struct as field bug

Files:

Legend:

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

    r564 r614  
    386386        /* There are problems doing this in the general case because 
    387387         * Scope keeps track of things like 'offset' 
    388388         */ 
    389389        if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
    390390        { 
    391391            //printf("setScope %s %s\n", s->kind(), s->toChars()); 
    392392            s->setScope(sc2); 
    393393        } 
    394394    } 
    395395 
    396396    for (int i = 0; i < members_dim; i++) 
    397397    { 
    398398        Dsymbol *s = (Dsymbol *)members->data[i]; 
    399399        s->semantic(sc2); 
    400400#if 0 
    401401        if (sizeok == 2) 
    402402        {   //printf("forward reference\n"); 
    403403            break; 
    404404        } 
    405405#endif 
     406 
     407#if 0   /* Decided to allow this because if the field is initialized by copying it from 
     408         * a correctly initialized struct, it will work. 
     409         */ 
    406410        Type *t; 
    407411        if (s->isDeclaration() && 
    408412            (t = s->isDeclaration()->type) != NULL && 
    409413            t->toBasetype()->ty == Tstruct) 
    410414        {   StructDeclaration *sd = (StructDeclaration *)t->toDsymbol(sc); 
    411415            if (sd->isnested) 
    412                 error("inner struct %s cannot be a field", sd->toChars()); 
    413         } 
     416                error("inner struct %s cannot be the type for field %s as it must embed a reference to its enclosing %s", 
     417                     sd->toChars(), s->toChars(), sd->toParent2()->toPrettyChars()); 
     418        } 
     419#endif 
    414420    } 
    415421 
    416422#if DMDV1 
    417423    /* This doesn't work for DMDV2 because (ref S) and (S) parameter 
    418424     * lists will overload the same. 
    419425     */ 
    420426    /* The TypeInfo_Struct is expecting an opEquals and opCmp with 
    421427     * a parameter that is a pointer to the struct. But if there 
    422428     * isn't one, but is an opEquals or opCmp with a value, write 
    423429     * another that is a shell around the value: 
    424430     *  int opCmp(struct *p) { return opCmp(*p); } 
    425431     */ 
    426432 
    427433    TypeFunction *tfeqptr; 
    428434    { 
    429435        Parameters *arguments = new Parameters; 
    430436        Parameter *arg = new Parameter(STCin, handle, Id::p, NULL); 
    431437 
    432438        arguments->push(arg); 
    433439        tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd);