Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve flow typing support for closures, instanceof and terminal blocks #521

Closed
eric-milles opened this issue Mar 8, 2018 · 0 comments
Closed
Assignees
Milestone

Comments

@eric-milles
Copy link
Member

eric-milles commented Mar 8, 2018

Flow typing support is very basic at the moment. As the inference engine moves through the statements of a block, variable assignments overwrite the inferred type of the assigned variable. This does not consider conditional paths like nested closure blocks or blocks that return/throw.

def m1(def x) {
  def cl = { ->
    x = 1
  }
  x // type remains Object because Closure is not executed
}
def m2(def x) {
  if (predicate()) {
    x = 1
    return 0
   }
  x // type remains Object because conditional block does not share path here
}
def m3(def x) {
  if (x instanceof CharSequence) {
    x = Integer.valueOf(x)
  }
  x // bug prevents assignment within instanceof guard from propagating type info
}
@eric-milles eric-milles added this to the v3.0.0 milestone Mar 8, 2018
eric-milles added a commit that referenced this issue Mar 9, 2018
- fix for declaring type of parameter nodes
- fix for instanceof with nested assignment
@eric-milles eric-milles self-assigned this Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant