Thread overview
[Issue 5435] New: Static foreach over tuple ignores type annotation
Jan 09, 2011
Max Klyga
Jan 09, 2011
Walter Bright
Jan 09, 2011
Brad Roberts
Jan 09, 2011
Brad Roberts
Jun 01, 2012
Kenji Hara
Jun 03, 2012
Walter Bright
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5435

           Summary: Static foreach over tuple ignores type annotation
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: necroment@gmail.com


--- Comment #0 from Max Klyga <necroment@gmail.com> 2011-01-08 18:29:56 PST ---
import std.stdio;

template Tuple(E...) { alias E Tuple; }
enum Type { A, B, C };
alias Tuple!(Type.A, Type.B, Type.C, "foo", 3.0) tuple;

void main() {
  foreach (Type foo; tuple)
    writeln(foo);
  foreach (string foo; tuple)
    writeln(foo);
  foreach (int foo; tuple)
    writeln(foo);
}
---------

This code compiles and runs without errors, printing every element of tuple.

Should the compiler reject static foreach with explicit type annotations ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |INVALID


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2011-01-08 21:19:31 PST ---
This behavior is as intended. Not a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr@puremagic.com


--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2011-01-08 21:24:51 PST ---
I think you ought to rethink your intention then.  Allowing a specific type but ignoring it is odd.  I think static foreach should require type deduction and error on anything else.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


--- Comment #3 from Brad Roberts <braddr@puremagic.com> 2011-01-08 23:27:48 PST ---
Reopening.  To be clear, I think the only two valid syntax's should be:

foreach(t; tuple) { ... }

or

foreach(auto t; tuple) { ... }

I could be convinced that specifying a type is ok, but only for the case of a tuple where all the values match the specified type.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, pull
           Platform|Other                       |All


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-01 09:59:04 PDT ---
https://github.com/D-Programming-Language/dmd/pull/977

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5435



--- Comment #5 from github-bugzilla@puremagic.com 2012-06-02 15:22:11 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e51d8953eac1665831ef598de95684f29c964208 fix Issue 5435 - Static foreach over tuple ignores type annotation

https://github.com/D-Programming-Language/dmd/commit/62d6363c59362025b0c809ee865dd52d78cbf33c Merge pull request #977 from 9rnsr/fix_foreach_arg

Issue 3290,4510,5435 - Add strict type check for foreach argument

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 03, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------