Skip to content

Can't return from inside a block #270

Closed

Description

@pcwalton

iterFunc({|| ret; }) does not return from the outer function.

Maybe we'll just have accept this, since in the absence of non-local control flow, there's no nice way to implement such returns.

Activity

  1. brson commented on Jun 21, 2011

    @brson
    Contributor

    This translates now, but incorrectly, acting like a continue statement.

  2. catamorphism commented on Jul 20, 2011

    @catamorphism
    Contributor

    Here's a code example that reproduces it:

    use std;
    import std::uint;
    
    fn foo() {
      for each (uint i in uint::range(0u, 10u)) { 
        if (i > 5u) {
          ret;
        }
      }
      fail "Shouldn't have reached this point";
    }
    
    fn main() {
      foo();
      log_err "Okay!";
    }
    

    The problem is that the ret inside the for-each loop is returning from the closure that trans generates automatically for the loop body, not from foo. That's why it acts like a continue.

    I was going to try fixing this, but it's not obvious to me how to (there's no other case when you're returning from more than one nested scope at once), so I'm changing it back to unassigned.

  3. marijnh commented on Oct 21, 2011

    @marijnh
    Contributor

    Iterators are out. Rewording the bug title to apply to blocks.

  4. graydon commented on Mar 5, 2012

    @graydon
    Contributor

    Duplicated (in much more detail) by #1619, closing.

  5. added a commit that references this issue on Nov 29, 2018
  6. added a commit that references this issue on Dec 9, 2021
  7. added a commit that references this issue on Aug 21, 2026
  8. added a commit that references this issue on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions