[Issue 21746] New: Discrepancy between foreach over tuple and static foreach
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 22 07:54:34 UTC 2021
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 at puremagic.com
Reporter: pro.mathias.lang at 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.
--
More information about the Digitalmars-d-bugs
mailing list