www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5435] New: Static foreach over tuple ignores type annotation

reply d-bugmail puremagic.com writes:
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



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: -------
Jan 08 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jan 08 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Brad Roberts <braddr puremagic.com> changed:

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



---
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: -------
Jan 08 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5435


Brad Roberts <braddr puremagic.com> changed:

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



---
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: -------
Jan 08 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jun 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5435




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


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: -------
Jun 02 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Jun 02 2012