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

Fix type inferencing and syntax highlighting for dynamic variable set within if and else blocks #1086

Closed
eric-milles opened this issue Apr 15, 2020 · 1 comment
Assignees
Milestone

Comments

@eric-milles
Copy link
Member

Consider the following:

File findFile(boolean condition) {
  def file
  if (condition) {
    file = new File(System.getProperty('user.home'), '.groovy')
  } else {
    file = new File(System.getProperty('groovy.root'))
  }
  file.canonicalFile
}

The last occurrence of "file" is showing as unknown (underlined). Since the variable is initialized to a java.io.File in both conditional branches, the type should propagate to the outer block.

image

@eric-milles eric-milles self-assigned this Apr 15, 2020
eric-milles added a commit that referenced this issue Apr 24, 2020
def file
if (condition) {
  file = new File(...)
} else {
  file = returnsFile()
}
// typeof(file) == File
@eric-milles
Copy link
Member Author

image

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