Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

If/else should have their own scopes #3

Open
lpereira opened this issue Apr 24, 2017 · 0 comments
Open

If/else should have their own scopes #3

lpereira opened this issue Apr 24, 2017 · 0 comments

Comments

@lpereira
Copy link
Owner

The following program:

func bla(xxx interface{}) {
        if f, ok := xxx.(int); ok {
                println("xxx is int", f)
        } else {
                f := xxx.(Foo)
                println("xxx is not int, it's Foo:", f.bar)
        }
}

Will generate the following program:

void bla(moku::empty_interface xxx) {
  {
    int f{0};
    bool ok{false};

    std::tie(f, ok) = moku::try_type_assert<int>(xxx);

    if (ok) {
      println("xxx is int", f);
    } else {
      f = moku::type_assert<Foo>(xxx);
      println("xxx is not int, it's Foo:", f.bar);
    }
  }
}

The type of f in the else block is clearly wrong. The if and else blocks should have their own scopes.

@lpereira lpereira reopened this Apr 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant