GROOVY-11375, GROOVY-11769: SC: lookup type of variable before target
There may be some side effects from changing StaticTypesTypeChooser in this manner. I cannot recall exactly why this was not ported to 4.x back in June 2024.
see also GROOVY-9344, GROOVY-9607
One of the related problems from Grails (see GormEntityTransformation) is this:
if (classNode instanceof InnerClassNode || classNode.isEnum())
The second occurrence of classNode gets cast to InnerClassNode due to improper or handling (see GROOVY-7971).
I am happy for this to be merged but we still need to sort out GROOVY-7971. I might try to relook at that again soon.
I'm reluctant to merge myself because GROOVY-11769 is about bytecode optimization, not failing functionality. And GROOVY-11375 was not strong enough on its own to make this change earlier.