D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4209 - Can not return from foreach over associative array
Summary: Can not return from foreach over associative array
Status: RESOLVED DUPLICATE of issue 4184
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-05-19 09:55 UTC by Jesse Phillips
Modified: 2014-02-15 02:45 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jesse Phillips 2010-05-19 09:55:33 UTC
The code below demonstrates that even though the function can only return 'false' it will return 'true' This is with DMD 2.043

void main() {
   assert(success() == false);
}


bool success() {
   auto arr = ["Hello":"Misty", "There":"Cats"];

   foreach(a; arr)
      if(a == "Cats") {
         return false;
      } else if(a == "Misty") {
      } else
         assert(false, "Should never get here.");

   return true;
}
Comment 1 Steven Schveighoffer 2010-05-19 10:15:28 UTC
This was recently fixed in 2.046.

Building your code with 2.046 compiles and runs as expected (no assertion).

*** This issue has been marked as a duplicate of issue 4184 ***
Comment 2 Jesse Phillips 2010-05-19 13:59:09 UTC
Thanks I would have never guessed they were the same issue.