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

Changeset 307

Show
Ignore:
Timestamp:
12/24/09 09:38:16 (15 years ago)
Author:
walter
Message:

bugzilla 3641 alias shared T U does not work

Files:

Legend:

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

    r305 r307  
    290290        st->htype = htype->syntaxCopy(); 
    291291    if (!hbasetype) 
    292292    {   if (basetype) 
    293293    {   hbasetype = basetype->syntaxCopy(); 
    294294        st->hbasetype = basetype->syntaxCopy(); 
    295295    } 
    296296    } 
    297297    else 
    298298        st->hbasetype = hbasetype->syntaxCopy(); 
    299299#endif 
    300300    return st; 
    301301} 
    302302 
    303303void TypedefDeclaration::semantic(Scope *sc) 
    304304{ 
    305305    //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); 
    306306    if (sem == 0) 
    307307    {   sem = 1; 
    308308    basetype = basetype->semantic(loc, sc); 
    309309    sem = 2; 
     310#if DMDV2 
     311    type = type->addStorageClass(storage_class); 
     312#endif 
    310313    type = type->semantic(loc, sc); 
    311314    if (sc->parent->isFuncDeclaration() && init) 
    312315        semantic2(sc); 
    313316    storage_class |= sc->stc & STCdeprecated; 
    314317    } 
    315318    else if (sem == 1) 
    316319    { 
    317320    error("circular definition"); 
    318321    } 
    319322} 
    320323 
    321324void TypedefDeclaration::semantic2(Scope *sc) 
    322325{ 
    323326    //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); 
    324327    if (sem == 2) 
    325328    {   sem = 3; 
    326329    if (init) 
    327330    { 
    328331        init = init->semantic(sc, basetype); 
    329332 
     
    421424        sa->haliassym = aliassym->syntaxCopy(s); 
    422425    } 
    423426    } 
    424427    else 
    425428    sa->haliassym = haliassym->syntaxCopy(s); 
    426429#endif 
    427430    return sa; 
    428431} 
    429432 
    430433void AliasDeclaration::semantic(Scope *sc) 
    431434{ 
    432435    //printf("AliasDeclaration::semantic() %s\n", toChars()); 
    433436    if (aliassym) 
    434437    { 
    435438    if (aliassym->isTemplateInstance()) 
    436439        aliassym->semantic(sc); 
    437440    return; 
    438441    } 
    439442    this->inSemantic = 1; 
    440443 
     444#if DMDV1   // don't really know why this is here 
    441445    if (storage_class & STCconst) 
    442446    error("cannot be const"); 
     447#endif 
    443448 
    444449    storage_class |= sc->stc & STCdeprecated; 
    445450 
    446451    // Given: 
    447452    //  alias foo.bar.abc def; 
    448453    // it is not knowable from the syntax whether this is an alias 
    449454    // for a type or an alias for a symbol. It is up to the semantic() 
    450455    // pass to distinguish. 
    451456    // If it is a type, then type is set and getType() will return that 
    452457    // type. If it is a symbol, then aliassym is set and type is NULL - 
    453458    // toAlias() will return aliasssym. 
    454459 
    455460    Dsymbol *s; 
    456461    Type *t; 
    457462    Expression *e; 
    458463 
    459464    /* This section is needed because resolve() will: 
    460465     *   const x = 3; 
    461466     *   alias x y; 
    462467     * try to alias y to 3. 
    463468     */ 
    464469    s = type->toDsymbol(sc); 
    465470    if (s && ((s->getType() && type->equals(s->getType())) || s->isEnumMember())) 
    466471    goto L2;            // it's a symbolic alias 
    467472 
    468473#if DMDV2 
     474    type = type->addStorageClass(storage_class); 
    469475    if (storage_class & (STCref | STCnothrow | STCpure)) 
    470476    {   // For 'ref' to be attached to function types, and picked 
    471477    // up by Type::resolve(), it has to go into sc. 
    472478    sc = sc->push(); 
    473     sc->stc |= storage_class & (STCref | STCnothrow | STCpure); 
     479    sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCshared); 
    474480    type->resolve(loc, sc, &e, &t, &s); 
    475481    sc = sc->pop(); 
    476482    } 
    477483    else 
    478484#endif 
    479485    type->resolve(loc, sc, &e, &t, &s); 
    480486    if (s) 
    481487    { 
    482488    goto L2; 
    483489    } 
    484490    else if (e) 
    485491    { 
    486492    // Try to convert Expression to Dsymbol 
    487493    s = getDsymbol(e); 
    488494    if (s) 
    489495        goto L2; 
    490496 
    491497    error("cannot alias an expression %s", e->toChars()); 
    492498    t = e->type; 
    493499    } 
  • trunk/src/opover.c

    r295 r307  
    533533 * Given array of arguments and an aggregate type, 
    534534 * if any of the argument types are missing, attempt to infer 
    535535 * them from the aggregate type. 
    536536 */ 
    537537 
    538538void inferApplyArgTypes(enum TOK op, Parameters *arguments, Expression *aggr) 
    539539{ 
    540540    if (!arguments || !arguments->dim) 
    541541    return; 
    542542 
    543543    /* Return if no arguments need types. 
    544544     */ 
    545545    for (size_t u = 0; 1; u++) 
    546546    {   if (u == arguments->dim) 
    547547        return; 
    548548    Parameter *arg = (Parameter *)arguments->data[u]; 
    549549    if (!arg->type) 
    550550        break; 
    551551    } 
    552552 
     553    Dsymbol *s; 
    553554    AggregateDeclaration *ad; 
    554555 
    555556    Parameter *arg = (Parameter *)arguments->data[0]; 
    556557    Type *taggr = aggr->type; 
    557558    if (!taggr) 
    558559    return; 
    559560    Type *tab = taggr->toBasetype(); 
    560561    switch (tab->ty) 
    561562    { 
    562563    case Tarray: 
    563564    case Tsarray: 
    564565    case Ttuple: 
    565566        if (arguments->dim == 2) 
    566567        { 
    567568        if (!arg->type) 
    568569            arg->type = Type::tsize_t;  // key type 
    569570        arg = (Parameter *)arguments->data[1]; 
    570571        } 
    571572        if (!arg->type && tab->ty != Ttuple) 
    572573        arg->type = tab->nextOf();  // value type 
     
    578579        if (arguments->dim == 2) 
    579580        { 
    580581        if (!arg->type) 
    581582            arg->type = taa->index; // key type 
    582583        arg = (Parameter *)arguments->data[1]; 
    583584        } 
    584585        if (!arg->type) 
    585586        arg->type = taa->next;      // value type 
    586587        break; 
    587588    } 
    588589 
    589590    case Tclass: 
    590591        ad = ((TypeClass *)tab)->sym; 
    591592        goto Laggr; 
    592593 
    593594    case Tstruct: 
    594595        ad = ((TypeStruct *)tab)->sym; 
    595596        goto Laggr; 
    596597 
    597598    Laggr: 
    598         Dsymbol *s = search_function(ad, 
     599        s = search_function(ad, 
    599600            (op == TOKforeach_reverse) ? Id::applyReverse 
    600601                           : Id::apply); 
    601602        if (s) 
    602603        goto Lapply;            // prefer opApply 
    603604 
    604605        if (arguments->dim == 1) 
    605606        { 
    606607        if (!arg->type) 
    607608        { 
    608609            /* Look for a head() or rear() overload 
    609610             */ 
    610611            Identifier *id = (op == TOKforeach) ? Id::Fhead : Id::Ftoe; 
    611612            Dsymbol *s = search_function(ad, id); 
    612613            FuncDeclaration *fd = s ? s->isFuncDeclaration() : NULL; 
    613614            if (!fd) 
    614615            {   if (s && s->isTemplateDeclaration()) 
    615616                break; 
    616617            goto Lapply; 
    617618            } 
    618619            arg->type = fd->type->nextOf();