[Issue 1245] static foreach shouldn't define new scope and introduce new variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 28 22:27:33 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1245





------- Comment #5 from baryluk at mpi.int.pl  2007-05-29 00:27 -------
Another example:

module staticforeach_switch;

import std.stdio;

template Tuple(E...) { alias E Tuple; }
alias Tuple!(101.0, 102.0, 103.0, 104.0) coef;

double f(int l, double x) {
   switch (l) {
     foreach (i, a_i; coef) {
        case i:
            //return x*a_i; // compiles and gives garbage
            return x*coef[i]; // works
      }
        default:
            assert(0);
   }
   assert(0);
}

void main() {
        writefln(f(3, 2.0)); // 2*104 = 208
}


-- 



More information about the Digitalmars-d-bugs mailing list