On 03.12.22 15:50, Christopher Smith wrote:
I believe the feature at play is "flow typing", and it surprises me that it would apply to variables declared with an explicit type. What version of Groovy are you targeting, and is this compiled statically or dynamically?
The declaration type is to be understood as an base type for the variable, not the flow type. Which means in Y foo = bar() foo.x() the flow type of foo is whatever is inferred as result type for the call bar(). The assignment to foo is valid if the result type for the call to bar() is assignable to Y. The call x() on foo is valid if the method x() exists on the flow type. This is the intended behaviour. bye Jochen