paulk-asert commented on PR #2999: URL: https://github.com/apache/groovy/pull/2999#issuecomment-6393598605
Thanks Daniel. 1, 4. Agreed. 2. Copilot flagged the same helper. I've switched it to StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf, which the method-reference half of this PR already uses, so both halves share one subtype rule. 3. Right. Field, property and array stores target the declared type, so they don't have the problem. A polluted List<String> stored into a CharSequence field keeps the StringBuilder both before and after this change. 5. Yes, deliberately: a cast where the narrower type is actually needed, as javac does. One thing worth recording: before this change, a value that wasn't of the narrowed type usually didn't throw. It was silently converted (a StringBuilder became its toString(), an Integer[] became a String[]), so this fixes wrong values as well as cast failures. Two shapes still convert, as they did before: a reassignment after a declaration whose own value was narrow (CharSequence cs = 'x'; cs = list.get(0)), and an uninitialised declaration followed by an assignment. There the variable's slot takes the narrow type that flow typing infers across all the assignments. Fixing that means typing the slot with the declared type everywhere, which is a broader codegen change, so I've raised GROOVY-12494 for it rather than grow this PR. -- 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]
