Bug 2781 – alias this doesn't work with foreach

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-01T19:15:00Z
Last change time
2015-06-09T01:18:03Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2009-04-01T19:15:18Z
struct Tuple(T...) { T data; alias data this; } void main() { Tuple!(uint, float) foo; foreach(elem; foo) {} // Error: Cannot infer type for elem. } The same applies when this is aliased to an array instead of a tuple.
Comment #1 by k.hara.pg — 2011-07-14T04:18:04Z
Comment #2 by hoganmeier — 2011-08-12T08:47:58Z
Yep, also fails for arrays. btw, adding the type to elem yields: Error: undefined identifier module test.opApply Error: opApply() function for StructType must return an int
Comment #3 by bugzilla — 2011-08-22T20:47:11Z
Comment #4 by hoganmeier — 2011-08-23T04:51:30Z
Still fails for arrays. struct Foo { int[] data; alias data this; } void main() { Foo foo; foreach(elem; foo) {} // Error: Cannot infer type for elem. }
Comment #5 by k.hara.pg — 2011-08-23T20:40:14Z
(In reply to comment #4) > Still fails for arrays. Which version did you use? Git master (0b47c51f13) can compile it in my environment (Windows 7 64bit).
Comment #6 by hoganmeier — 2011-08-24T04:49:52Z
Sorry something must have gone wrong when I compiled dmd. It does work with arrays now.