Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

split init and conditionals that return or throw #14815

Closed
mppf opened this issue Jan 24, 2020 · 2 comments
Closed

split init and conditionals that return or throw #14815

mppf opened this issue Jan 24, 2020 · 2 comments

Comments

@mppf
Copy link
Member

mppf commented Jan 24, 2020

Should a program using split-init such as the below be allowed?

proc test() {
  var a;
  if option then
    a = new R(1);
  else
    return;
  
  moreStatements(a);
}

PR #14814 implements this, but previous to that PR, this program would not compile, because the else branch of the conditional does not initialize a.

However it is not a problem for this program to compile as-is, because moreStatements(a) will always access an initialized a, and a will simply not be initialized (or deinitialized) if the else branch is taken.

This feature is motivated by an example using try inspired by Arkouda: #14748 (comment) but if we allow this rule for catch clauses it would make sense to also allow for conditionals. (Issue #14748 discusses whether split-init should be allowed within try statements at all, but try/catch is notionally related to if/else and so we would probably make the same choice for return/throw).

@vasslitvinov
Copy link
Member

I agree that such programs should be allowed.

@mppf
Copy link
Member Author

mppf commented Jan 28, 2020

There seems to be agreement that such programs should be allowed. PR #14814 implements it and updates the spec. So I am closing this issue.

@mppf mppf closed this as completed Jan 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants