paulk-asert commented on PR #2998: URL: https://github.com/apache/groovy/pull/2998#issuecomment-6393228177
Thanks Daniel. 1. A recursive return edge contributes the declared type (Object), so the result is Object rather than something wider than the base cases: nothing is inferred for such a method. testRecursiveCallUsesDeclaredType pins that (countdown(n) returning 'done' or countdown(n - 1) still fails on .toUpperCase()). 2. Agreed. 3. Good idea. I've added a test that pins pick(name()) selecting pick(String) under @CompileStatic. 4. Agreed, that's why it's spelled out in COMPATIBILITY.md. 5. On checking, the exclusion isn't needed. An enum with constant bodies is already non-final by the time type checking runs, in the class file as well, and a plain enum is final. So the final-class test already does the right thing, and the extra !type.isEnum() only kept methods of plain enums from being inferred. I've removed it and added tests for both shapes: a plain enum gets the inferred type, and a method overridden in a constant body keeps the declared one. 6. One refinement: under @TypeChecked, a static method called through its class name (A.name()), or from a static context, does get the inferred type, because there the call can't reach a subclass. Only instance-receiver calls such as this.name(), or calls from a closure, keep the declared type. testTypeCheckedStaticMethodViaClass and testTypeCheckedPrivateOrStaticMethodViaInstance cover the two sides. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
