www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21746] New: Discrepancy between foreach over tuple and static

https://issues.dlang.org/show_bug.cgi?id=21746

          Issue ID: 21746
           Summary: Discrepancy between foreach over tuple and static
                    foreach
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

```
import std.meta;
import std.stdio;

void main ()
{
    foreach (idx, T; AliasSeq!(int, char, bool, int, string, int, ubyte))
    {
        void checkValue (TT) (TT value, size_t id)
        {
            assert(id == idx);
            assert(value == TT.init);
        }
        checkValue(T.init, idx);
    }
    writeln("Yep");
}
```

Since the fix for https://issues.dlang.org/show_bug.cgi?id=14831 this runs
correctly. However trying to make the `foreach` static will lead to the
following errors:
```
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
foo.d(8): Error: declaration `checkValue(TT)(TT value, size_t id)` is already
defined
foo.d(8):        `template` `checkValue(TT)(TT value, size_t id)` is defined
here
```

Obviously this is an unwarranted limitation.

--
Mar 22