Hi Daniel, We discussed this when we implemented static compilation in the past. There were 2 different relates cases discussed:
- smarter type inference for final fields - smarter type inference for final methods and decided not to implement them, so that it's not confusing for users when the compiler can infer a type in one case and not the other. We can revisit the decision, just want to give more context. Basically, it's not easy to realize that when you have a non final methods, subclasses can override the method to return a different type. Le mer. 5 sept. 2018 à 06:50, Daniel Sun <realblue...@hotmail.com> a écrit : > Hi all, > > I am going to refine the type inference of method return value, the > methods should match one of the following charactristics: > 1) `final` > 2) `private` > 3) `static` > 4) method defined in Script > > The above methods will not be overrided and have exact method return > type. > > Any thoughts? > > P.S. Currently the following code will fail to compile, but it's > obiviously valid. > ``` > @groovy.transform.CompileStatic > class Test { > static m() { > return 'abc' > } > > static a() { > return m().length() > } > > static void main(String[] args) { > assert 3 == a() > } > } > ``` > > Cheers, > Daniel.Sun > > > > > -- > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html >