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

Changeset 477

Show
Ignore:
Timestamp:
05/10/10 02:59:48 (15 years ago)
Author:
walter
Message:

bugzilla 4042 Unable to instantiate a struct template.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/class.c

    r451 r477  
    319319 
    320320                    tc->checkDeprecated(loc, sc); 
    321321                } 
    322322            } 
    323323 
    324324            if (tc->sym->isInterfaceDeclaration()) 
    325325                ; 
    326326            else 
    327327            { 
    328328                for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) 
    329329                { 
    330330                    if (cdb == this) 
    331331                    { 
    332332                        error("circular inheritance"); 
    333333                        baseclasses.remove(0); 
    334334                        goto L7; 
    335335                    } 
    336336                } 
    337337                if (!tc->sym->symtab || tc->sym->sizeok == 0) 
    338338                {   // Try to resolve forward reference 
    339                     if (sc->mustsemantic && tc->sym->scope) 
     339                    if (/*sc->mustsemantic &&*/ tc->sym->scope) 
    340340                        tc->sym->semantic(NULL); 
    341341                } 
    342342                if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 
    343343                { 
    344344                    //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 
    345345                    //error("forward reference of base class %s", baseClass->toChars()); 
    346346                    // Forward reference of base class, try again later 
    347347                    //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 
    348348                    scope = scx ? scx : new Scope(*sc); 
    349349                    scope->setNoFree(); 
    350350                    if (tc->sym->scope) 
    351351                        tc->sym->scope->module->addDeferredSemantic(tc->sym); 
    352352                    scope->module->addDeferredSemantic(this); 
    353353                    return; 
    354354                } 
    355355                else 
    356356                {   baseClass = tc->sym; 
    357357                    b->base = baseClass; 
    358358                } 
    359359             L7: ; 
     
    387387            { 
    388388                if (!isDeprecated()) 
    389389                { 
    390390                    // Deriving from deprecated class makes this one deprecated too 
    391391                    isdeprecated = 1; 
    392392 
    393393                    tc->checkDeprecated(loc, sc); 
    394394                } 
    395395            } 
    396396 
    397397            // Check for duplicate interfaces 
    398398            for (size_t j = (baseClass ? 1 : 0); j < i; j++) 
    399399            { 
    400400                BaseClass *b2 = (BaseClass *)baseclasses.data[j]; 
    401401                if (b2->base == tc->sym) 
    402402                    error("inherits from duplicate interface %s", b2->base->toChars()); 
    403403            } 
    404404 
    405405            if (!tc->sym->symtab) 
    406406            {   // Try to resolve forward reference 
    407                 if (sc->mustsemantic && tc->sym->scope) 
     407                if (/*sc->mustsemantic &&*/ tc->sym->scope) 
    408408                    tc->sym->semantic(NULL); 
    409409            } 
    410410 
    411411            b->base = tc->sym; 
    412412            if (!b->base->symtab || b->base->scope) 
    413413            { 
    414414                //error("forward reference of base class %s", baseClass->toChars()); 
    415415                // Forward reference of base, try again later 
    416416                //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 
    417417                scope = scx ? scx : new Scope(*sc); 
    418418                scope->setNoFree(); 
    419419                if (tc->sym->scope) 
    420420                    tc->sym->scope->module->addDeferredSemantic(tc->sym); 
    421421                scope->module->addDeferredSemantic(this); 
    422422                return; 
    423423            } 
    424424        } 
    425425        i++; 
    426426    } 
    427427 
  • branches/dmd-1.x/src/template.c

    r428 r477  
    34853485        } 
    34863486#endif 
    34873487    } 
    34883488 
    34893489  Laftersemantic: 
    34903490    sc2->pop(); 
    34913491 
    34923492    scope->pop(); 
    34933493 
    34943494    // Give additional context info if error occurred during instantiation 
    34953495    if (global.errors != errorsave) 
    34963496    { 
    34973497        error("error instantiating"); 
    34983498        if (tinst) 
    34993499        {   tinst->printInstantiationTrace(); 
    35003500            if (!global.gag) 
    35013501                fatal(); 
    35023502        } 
    35033503        errors = 1; 
    35043504        if (global.gag) 
     3505        {   // Try to reset things so we can try again later to instantiate it 
    35053506            tempdecl->instances.remove(tempdecl_instance_idx); 
     3507            semanticRun = 0; 
     3508            inst = NULL; 
     3509        } 
    35063510    } 
    35073511 
    35083512#if LOG 
    35093513    printf("-TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 
    35103514#endif 
    35113515} 
    35123516 
    35133517 
    35143518void TemplateInstance::semanticTiargs(Scope *sc) 
    35153519{ 
    35163520    //printf("+TemplateInstance::semanticTiargs() %s\n", toChars()); 
    35173521    if (semantictiargsdone) 
    35183522        return; 
    35193523    semantictiargsdone = 1; 
    35203524    semanticTiargs(loc, sc, tiargs, 0); 
    35213525} 
    35223526 
    35233527/********************************** 
    35243528 * Input: 
    35253529 *      flags   1: replace const variables with their initializers 
  • trunk/src/class.c

    r450 r477  
    327327 
    328328                    tc->checkDeprecated(loc, sc); 
    329329                } 
    330330            } 
    331331 
    332332            if (tc->sym->isInterfaceDeclaration()) 
    333333                ; 
    334334            else 
    335335            { 
    336336                for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) 
    337337                { 
    338338                    if (cdb == this) 
    339339                    { 
    340340                        error("circular inheritance"); 
    341341                        baseclasses.remove(0); 
    342342                        goto L7; 
    343343                    } 
    344344                } 
    345345                if (!tc->sym->symtab || tc->sym->sizeok == 0) 
    346346                {   // Try to resolve forward reference 
    347                     if (sc->mustsemantic && tc->sym->scope) 
     347                    if (/*sc->mustsemantic &&*/ tc->sym->scope) 
    348348                        tc->sym->semantic(NULL); 
    349349                } 
    350350                if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 
    351351                { 
    352                     //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 
     352                    printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 
    353353                    //error("forward reference of base class %s", baseClass->toChars()); 
    354354                    // Forward reference of base class, try again later 
    355355                    //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 
    356356                    scope = scx ? scx : new Scope(*sc); 
    357357                    scope->setNoFree(); 
    358358                    if (tc->sym->scope) 
    359359                        tc->sym->scope->module->addDeferredSemantic(tc->sym); 
    360360                    scope->module->addDeferredSemantic(this); 
    361361                    return; 
    362362                } 
    363363                else 
    364364                {   baseClass = tc->sym; 
    365365                    b->base = baseClass; 
    366366                } 
    367367             L7: ; 
    368368            } 
    369369        } 
    370370    } 
    371371 
    372372    // Treat the remaining entries in baseclasses as interfaces 
     
    395395            { 
    396396                if (!isDeprecated()) 
    397397                { 
    398398                    // Deriving from deprecated class makes this one deprecated too 
    399399                    isdeprecated = 1; 
    400400 
    401401                    tc->checkDeprecated(loc, sc); 
    402402                } 
    403403            } 
    404404 
    405405            // Check for duplicate interfaces 
    406406            for (size_t j = (baseClass ? 1 : 0); j < i; j++) 
    407407            { 
    408408                BaseClass *b2 = (BaseClass *)baseclasses.data[j]; 
    409409                if (b2->base == tc->sym) 
    410410                    error("inherits from duplicate interface %s", b2->base->toChars()); 
    411411            } 
    412412 
    413413            if (!tc->sym->symtab) 
    414414            {   // Try to resolve forward reference 
    415                 if (sc->mustsemantic && tc->sym->scope) 
     415                if (/*sc->mustsemantic &&*/ tc->sym->scope) 
    416416                    tc->sym->semantic(NULL); 
    417417            } 
    418418 
    419419            b->base = tc->sym; 
    420420            if (!b->base->symtab || b->base->scope) 
    421421            { 
    422422                //error("forward reference of base class %s", baseClass->toChars()); 
    423423                // Forward reference of base, try again later 
    424424                //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 
    425425                scope = scx ? scx : new Scope(*sc); 
    426426                scope->setNoFree(); 
    427427                if (tc->sym->scope) 
    428428                    tc->sym->scope->module->addDeferredSemantic(tc->sym); 
    429429                scope->module->addDeferredSemantic(this); 
    430430                return; 
    431431            } 
    432432        } 
    433433        i++; 
    434434    } 
    435435 
  • trunk/src/declaration.c

    r474 r477  
    511511        if (f) 
    512512        { 
    513513            if (overnext) 
    514514            { 
    515515                FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 
    516516                if (!fa->overloadInsert(overnext)) 
    517517                    ScopeDsymbol::multiplyDefined(0, f, overnext); 
    518518                overnext = NULL; 
    519519                s = fa; 
    520520                s->parent = sc->parent; 
    521521            } 
    522522        } 
    523523        if (overnext) 
    524524            ScopeDsymbol::multiplyDefined(0, s, overnext); 
    525525        if (s == this) 
    526526        { 
    527527            assert(global.errors); 
    528528            s = NULL; 
    529529        } 
    530530    } 
    531     //printf("setting aliassym %p to %p\n", this, s); 
     531    //printf("setting aliassym %s to %s %s\n", toChars(), s->kind(), s->toChars()); 
    532532    aliassym = s; 
    533533    this->inSemantic = 0; 
    534534} 
    535535 
    536536int AliasDeclaration::overloadInsert(Dsymbol *s) 
    537537{ 
    538538    /* Don't know yet what the aliased symbol is, so assume it can 
    539539     * be overloaded and check later for correctness. 
    540540     */ 
    541541 
    542542    //printf("AliasDeclaration::overloadInsert('%s')\n", s->toChars()); 
    543543    if (aliassym) // see test/test56.d 
    544544    { 
    545545        Dsymbol *a = aliassym->toAlias(); 
    546546        FuncDeclaration *f = a->isFuncDeclaration(); 
    547547        if (f)  // BUG: what if it's a template? 
    548548        { 
    549549            FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 
    550550            aliassym = fa; 
    551551            return fa->overloadInsert(s); 
  • trunk/src/expression.c

    r473 r477  
    258258                     s = s->toParent()) 
    259259                {   FuncDeclaration *f = s->isFuncDeclaration(); 
    260260                    if (f->vthis) 
    261261                    { 
    262262                        //printf("rewriting e1 to %s's this\n", f->toChars()); 
    263263                        n++; 
    264264                        e1 = new VarExp(loc, f->vthis); 
    265265                    } 
    266266                } 
    267267                if (s && s->isClassDeclaration()) 
    268268                {   e1->type = s->isClassDeclaration()->type; 
    269269                    if (n > 1) 
    270270                        e1 = e1->semantic(sc); 
    271271                } 
    272272                else 
    273273                    e1 = e1->semantic(sc); 
    274274                goto L1; 
    275275            } 
    276276            /* Can't find a path from e1 to ad 
    277277             */ 
     278printf("t->ty = %d\n", t->ty); 
    278279            e1->error("this for %s needs to be type %s not type %s", 
    279280                var->toChars(), ad->toChars(), t->toChars()); 
    280281            e1 = new ErrorExp(); 
    281282        } 
    282283    } 
    283284    return e1; 
    284285} 
    285286 
    286287/***************************************** 
    287288 * Determine if 'this' is available. 
    288289 * If it is, return the FuncDeclaration that has it. 
    289290 */ 
    290291 
    291292FuncDeclaration *hasThis(Scope *sc) 
    292293{   FuncDeclaration *fd; 
    293294    FuncDeclaration *fdthis; 
    294295 
    295296    //printf("hasThis()\n"); 
    296297    fdthis = sc->parent->isFuncDeclaration(); 
    297298    //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : ""); 
     
    10591060 
    10601061Expression *Expression::semantic(Scope *sc) 
    10611062{ 
    10621063#if LOGSEMANTIC 
    10631064    printf("Expression::semantic() %s\n", toChars()); 
    10641065#endif 
    10651066    if (type) 
    10661067        type = type->semantic(loc, sc); 
    10671068    else 
    10681069        type = Type::tvoid; 
    10691070    return this; 
    10701071} 
    10711072 
    10721073/********************************** 
    10731074 * Try to run semantic routines. 
    10741075 * If they fail, return NULL. 
    10751076 */ 
    10761077 
    10771078Expression *Expression::trySemantic(Scope *sc) 
    10781079{ 
     1080    //printf("+trySemantic(%s)\n", toChars()); 
    10791081    unsigned errors = global.errors; 
    10801082    global.gag++; 
    10811083    Expression *e = semantic(sc); 
    10821084    global.gag--; 
    10831085    if (errors != global.errors) 
    10841086    { 
    10851087        global.errors = errors; 
    10861088        e = NULL; 
    10871089    } 
     1090    //printf("-trySemantic(%s)\n", toChars()); 
    10881091    return e; 
    10891092} 
    10901093 
    10911094void Expression::print() 
    10921095{ 
    10931096    fprintf(stdmsg, "%s\n", toChars()); 
    10941097    fflush(stdmsg); 
    10951098} 
    10961099 
    10971100char *Expression::toChars() 
    10981101{   OutBuffer *buf; 
    10991102    HdrGenState hgs; 
    11001103 
    11011104    memset(&hgs, 0, sizeof(hgs)); 
    11021105    buf = new OutBuffer(); 
    11031106    toCBuffer(buf, &hgs); 
    11041107    return buf->toChars(); 
    11051108} 
    11061109 
    11071110void Expression::error(const char *format, ...) 
  • trunk/src/mtype.c

    r462 r477  
    298298} 
    299299 
    300300d_uns64 Type::size(Loc loc) 
    301301{ 
    302302    error(loc, "no size for type %s", toChars()); 
    303303    return 1; 
    304304} 
    305305 
    306306unsigned Type::alignsize() 
    307307{ 
    308308    return size(0); 
    309309} 
    310310 
    311311Type *Type::semantic(Loc loc, Scope *sc) 
    312312{ 
    313313    return merge(); 
    314314} 
    315315 
    316316Type *Type::trySemantic(Loc loc, Scope *sc) 
    317317{ 
     318    //printf("+trySemantic(%s) %d\n", toChars(), global.errors); 
    318319    unsigned errors = global.errors; 
    319320    global.gag++;                       // suppress printing of error messages 
    320321    Type *t = semantic(loc, sc); 
    321322    global.gag--; 
    322323    if (errors != global.errors)        // if any errors happened 
    323324    { 
    324325        global.errors = errors; 
    325326        t = NULL; 
    326327    } 
     328    //printf("-trySemantic(%s) %d\n", toChars(), global.errors); 
    327329    return t; 
    328330} 
    329331 
    330332/******************************* 
    331333 * Determine if converting 'this' to 'to' is an identity operation, 
    332334 * a conversion to const operation, or the types aren't the same. 
    333335 * Returns: 
    334336 *      MATCHequal      'this' == 'to' 
    335337 *      MATCHconst      'to' is const 
    336338 *      MATCHnomatch    conversion to mutable or invariant 
    337339 */ 
    338340 
    339341MATCH Type::constConv(Type *to) 
    340342{ 
    341343    if (equals(to)) 
    342344        return MATCHexact; 
    343345    if (ty == to->ty && MODimplicitConv(mod, to->mod)) 
    344346        return MATCHconst; 
    345347    return MATCHnomatch; 
    346348} 
  • trunk/src/template.c

    r448 r477  
    35093509 
    35103510    if (s) 
    35113511        ti = (TemplateInstance *)s; 
    35123512    else 
    35133513        ti = new TemplateInstance(loc, name); 
    35143514 
    35153515    ti->tiargs = arraySyntaxCopy(tiargs); 
    35163516 
    35173517    ScopeDsymbol::syntaxCopy(ti); 
    35183518    return ti; 
    35193519} 
    35203520 
    35213521 
    35223522void TemplateInstance::semantic(Scope *sc) 
    35233523{ 
    35243524    semantic(sc, NULL); 
    35253525} 
    35263526 
    35273527void TemplateInstance::semantic(Scope *sc, Expressions *fargs) 
    35283528{ 
     3529    //printf("TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 
    35293530    if (global.errors && name != Id::AssociativeArray) 
    35303531    { 
     3532        //printf("not instantiating %s due to %d errors\n", toChars(), global.errors); 
    35313533        if (!global.gag) 
    35323534        { 
    35333535            /* Trying to soldier on rarely generates useful messages 
    35343536             * at this point. 
    35353537             */ 
    35363538            fatal(); 
    35373539        } 
    3538         return; 
     3540//        return; 
    35393541    } 
    35403542#if LOG 
    35413543    printf("\n+TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 
    35423544#endif 
    35433545    if (inst)           // if semantic() was already run 
    35443546    { 
    35453547#if LOG 
    35463548        printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); 
    35473549#endif 
    35483550        return; 
    35493551    } 
    35503552 
    35513553    // get the enclosing template instance from the scope tinst 
    35523554    tinst = sc->tinst; 
    35533555 
    35543556    if (semanticRun != 0) 
    35553557    { 
     3558#if LOG 
     3559        printf("Recursive template expansion\n"); 
     3560#endif 
    35563561        error(loc, "recursive template expansion"); 
    35573562//      inst = this; 
    35583563        return; 
    35593564    } 
    35603565    semanticRun = 1; 
    35613566 
    35623567#if LOG 
    35633568    printf("\tdo semantic\n"); 
    35643569#endif 
    35653570    if (havetempdecl) 
    35663571    { 
    35673572        assert((size_t)tempdecl->scope > 0x10000); 
    35683573        // Deduce tdtypes 
    35693574        tdtypes.setDim(tempdecl->parameters->dim); 
    35703575        if (!tempdecl->matchWithInstance(this, &tdtypes, 2)) 
    35713576        { 
    35723577            error("incompatible arguments for template instantiation"); 
    35733578            inst = this; 
    35743579            return; 
    35753580        } 
     
    39013906            error("recursive expansion"); 
    39023907            fatal(); 
    39033908        } 
    39043909#endif 
    39053910    } 
    39063911 
    39073912  Laftersemantic: 
    39083913    sc2->pop(); 
    39093914 
    39103915    scope->pop(); 
    39113916 
    39123917    // Give additional context info if error occurred during instantiation 
    39133918    if (global.errors != errorsave) 
    39143919    { 
    39153920        error("error instantiating"); 
    39163921        if (tinst) 
    39173922        {   tinst->printInstantiationTrace(); 
    39183923        } 
    39193924        errors = 1; 
    39203925        if (global.gag) 
     3926        {   // Try to reset things so we can try again later to instantiate it 
    39213927            tempdecl->instances.remove(tempdecl_instance_idx); 
     3928            semanticRun = 0; 
     3929            inst = NULL; 
     3930        } 
    39223931    } 
    39233932 
    39243933#if LOG 
    39253934    printf("-TemplateInstance::semantic('%s', this=%p)\n", toChars(), this); 
    39263935#endif 
    39273936} 
    39283937 
    39293938 
    39303939void TemplateInstance::semanticTiargs(Scope *sc) 
    39313940{ 
    39323941    //printf("+TemplateInstance::semanticTiargs() %s\n", toChars()); 
    39333942    if (semantictiargsdone) 
    39343943        return; 
    39353944    semantictiargsdone = 1; 
    39363945    semanticTiargs(loc, sc, tiargs, 0); 
    39373946} 
    39383947 
    39393948/********************************** 
    39403949 * Input: 
    39413950 *      flags   1: replace const variables with their initializers