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

Changeset 586

Show
Ignore:
Timestamp:
07/24/10 23:23:26 (14 years ago)
Author:
walter
Message:

bugzilla 3560 foreach over nested function generates wrong code

Files:

Legend:

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

    r567 r586  
    18121812                int j = sprintf(fdname, "_aApply%s%.*s%zd", r, 2, fntab[flag], dim); 
    18131813                assert(j < sizeof(fdname)); 
    18141814                FuncDeclaration *fdapply = FuncDeclaration::genCfunc(Type::tindex, fdname); 
    18151815 
    18161816                ec = new VarExp(0, fdapply); 
    18171817                Expressions *exps = new Expressions(); 
    18181818                if (tab->ty == Tsarray) 
    18191819                   aggr = aggr->castTo(sc, tn->arrayOf()); 
    18201820                exps->push(aggr); 
    18211821                exps->push(flde); 
    18221822                e = new CallExp(loc, ec, exps); 
    18231823                e->type = Type::tindex; // don't run semantic() on e 
    18241824            } 
    18251825            else if (tab->ty == Tdelegate) 
    18261826            { 
    18271827                /* Call: 
    18281828                 *      aggr(flde) 
    18291829                 */ 
    18301830                Expressions *exps = new Expressions(); 
    18311831                exps->push(flde); 
    1832                 e = new CallExp(loc, aggr, exps); 
     1832                if (aggr->op == TOKdelegate && 
     1833                    ((DelegateExp *)aggr)->func->isNested()) 
     1834                    // See Bugzilla 3560 
     1835                    e = new CallExp(loc, ((DelegateExp *)aggr)->e1, exps); 
     1836                else 
     1837                    e = new CallExp(loc, aggr, exps); 
    18331838                e = e->semantic(sc); 
    18341839                if (e->type != Type::tint32) 
    18351840                    error("opApply() function for %s must return an int", tab->toChars()); 
    18361841            } 
    18371842            else 
    18381843            { 
    18391844                /* Call: 
    18401845                 *      aggr.apply(flde) 
    18411846                 */ 
    18421847                ec = new DotIdExp(loc, aggr, 
    18431848                        (op == TOKforeach_reverse) ? Id::applyReverse 
    18441849                                                   : Id::apply); 
    18451850                Expressions *exps = new Expressions(); 
    18461851                exps->push(flde); 
    18471852                e = new CallExp(loc, ec, exps); 
    18481853                e = e->semantic(sc); 
    18491854                if (e->type != Type::tint32) 
    18501855                    error("opApply() function for %s must return an int", tab->toChars()); 
    18511856            } 
    18521857 
  • trunk/src/statement.c

    r567 r586  
    18781878                int j = sprintf(fdname, "_aApply%s%.*s%zd", r, 2, fntab[flag], dim); 
    18791879                assert(j < sizeof(fdname)); 
    18801880                FuncDeclaration *fdapply = FuncDeclaration::genCfunc(Type::tindex, fdname); 
    18811881 
    18821882                ec = new VarExp(0, fdapply); 
    18831883                Expressions *exps = new Expressions(); 
    18841884                if (tab->ty == Tsarray) 
    18851885                   aggr = aggr->castTo(sc, tn->arrayOf()); 
    18861886                exps->push(aggr); 
    18871887                exps->push(flde); 
    18881888                e = new CallExp(loc, ec, exps); 
    18891889                e->type = Type::tindex; // don't run semantic() on e 
    18901890            } 
    18911891            else if (tab->ty == Tdelegate) 
    18921892            { 
    18931893                /* Call: 
    18941894                 *      aggr(flde) 
    18951895                 */ 
    18961896                Expressions *exps = new Expressions(); 
    18971897                exps->push(flde); 
    1898                 e = new CallExp(loc, aggr, exps); 
     1898                if (aggr->op == TOKdelegate && 
     1899                    ((DelegateExp *)aggr)->func->isNested()) 
     1900                    // See Bugzilla 3560 
     1901                    e = new CallExp(loc, ((DelegateExp *)aggr)->e1, exps); 
     1902                else 
     1903                    e = new CallExp(loc, aggr, exps); 
    18991904                e = e->semantic(sc); 
    19001905                if (e->type != Type::tint32) 
    19011906                    error("opApply() function for %s must return an int", tab->toChars()); 
    19021907            } 
    19031908            else 
    19041909            { 
    19051910                assert(tab->ty == Tstruct || tab->ty == Tclass); 
    19061911                Expressions *exps = new Expressions(); 
    19071912                if (!sapply) 
    19081913                    sapply = search_function((AggregateDeclaration *)tab->toDsymbol(sc), idapply); 
    19091914#if 0 
    19101915                TemplateDeclaration *td; 
    19111916                if (sapply && 
    19121917                    (td = sapply->isTemplateDeclaration()) != NULL) 
    19131918                {   /* Call: 
    19141919                     *  aggr.apply!(fld)() 
    19151920                     */ 
    19161921                    Objects *tiargs = new Objects(); 
    19171922                    tiargs->push(fld); 
    19181923                    ec = new DotTemplateInstanceExp(loc, aggr, idapply, tiargs);