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

Extend type inferencing of dynamic field or property assigned in constructor or initialization method #1080

Closed
monrealis opened this issue Apr 11, 2020 · 5 comments
Assignees
Milestone

Comments

@monrealis
Copy link

monrealis commented Apr 11, 2020

It seems that the correct type is inferred only in the simple way where assignment is made at the location of declaration. Maybe it can be improved?

image

It does not work, for example, when def variable is assigned in Spock's setup().

Related article from 2009: http://contraptionsforprogramming.blogspot.com/2009/11/how-type-inferencing-for-groovy-in.html

@eric-milles eric-milles changed the title Groovy-Eclipse does not detect type of def variable Extend type inferencing of dynamic field or property assigned in constructor or initialization method Apr 11, 2020
@eric-milles eric-milles self-assigned this Apr 12, 2020
@eric-milles eric-milles added this to the v3.8.0 milestone Apr 13, 2020
@eric-milles
Copy link
Member

image

@eric-milles
Copy link
Member

This is testable for assignment in constructor or initializer block. If that looks good, an additional change will be made to support post-construct and other well-known initializer methods (like Spock's setup).

@monrealis
Copy link
Author

monrealis commented Apr 14, 2020

Thanks. Since there is no 100% guarantee that the value will not be overwritten with the value of another type from anywhere anyway, it would make sense not to worry too much about false inference and to look for the assignment anywhere, not only in the well-known initializer methods. For example, there may be two Spock tests that assign the value in given section with no assignment in setup.

@eric-milles
Copy link
Member

Did you have a chance to test what was implemented? This is not one of those 100% enhancements. Only common cases are going to be properly supported. See also #1056 (odd switch case structures will not infer properly).

@eric-milles
Copy link
Member

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

2 participants