GROOVY-11375, GROOVY-11769: SC: lookup type of variable before target#2311
GROOVY-11375, GROOVY-11769: SC: lookup type of variable before target#2311eric-milles wants to merge 1 commit intoGROOVY_4_0_Xfrom
Conversation
|
One of the related problems from Grails (see GormEntityTransformation) is this: if (classNode instanceof InnerClassNode || classNode.isEnum())The second occurrence of |
|
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. |
c8ff8c1 to
51538f2
Compare
see also GROOVY-7971, GROOVY-9344, GROOVY-9607 4_0_X backport
904e559 to
aec028c
Compare
There was a problem hiding this comment.
Pull request overview
This PR changes static-compilation type resolution to prefer metadata on the current expression before falling back to the accessed target, and adds regression tests around primitive flow typing and object-to-interface casts. In the Groovy codebase, this primarily affects how statically compiled bytecode decides operand and cast types after STC has attached flow-type metadata.
Changes:
- Update
StaticTypesTypeChooserto read inferred/declaration types from the expression first, then fall back to the accessed variable target. - Add/override regression tests for primitive flow typing in n-ary expressions and object-to-interface casting under static compilation.
- Replace a former
@NotYetImplementedinstanceoftest with a new GROOVY-11769 scenario.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java |
Changes SC type lookup order between expression metadata and accessed-variable metadata. |
src/test/groovy/groovy/transform/stc/STCAssignmentTest.groovy |
Adds assignment/cast regression coverage for object-to-interface conversion. |
src/test/groovy/org/codehaus/groovy/classgen/asm/sc/AssignmentsStaticCompileTest.groovy |
Adds bytecode-level assertion for the cast regression under static compilation. |
src/test/groovy/groovy/transform/stc/STCnAryExpressionTest.groovy |
Adds regression tests for flow-typed primitive shift and power operators. |
src/test/groovy/groovy/transform/stc/TypeInferenceSTCTest.groovy |
Replaces an old instanceof regression test with a new scenario intended to cover GROOVY-11769. |
| if (inferredType == null) { | ||
| inferredType = target.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); | ||
| ASTNode node = getTarget(exp); // GROOVY-9344, GROOVY-9607 | ||
| inferredType = node.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); |
| // GROOVY-11769 | ||
| void testInstanceOf10() { |
|
|
||
| void test(Foo foo) { | ||
| if (foo instanceof Bar || foo.isBaz()) { | ||
| foo.toString() |
There may be some side effects from changing
StaticTypesTypeChooserin this manner. I cannot recall exactly why this was not ported to 4.x back in June 2024.see also GROOVY-9344, GROOVY-9607