Skip to content

Conversation

@eric-milles
Copy link
Member

@eric-milles eric-milles commented Dec 10, 2025

NOTE: I still have some refactoring to do to make the push/pop/peek interactions with the temp type info data structure a bit better. I thought I would get this in front of you to see the solution design. I also try not to use union and intersection to maintain clarity.

see also #1293 and #1269

if (x instanceof String || x instanceof Number || x instanceof Pattern)
    x.something()
switch (x) {
  case String:
  case Number:
  case Pattern:
    x.something()
}

Treat both of these cases as typeof(x) is (String | Number | Pattern) for STC. Maybe extend to catch (Exception | Error e).

The UnionTypeClassNode represents the any-of type alternatives, as described in its javadoc. So use it for that, not for all-of types. LowestUpperBoundClassNode is one type that represents (Type & Serializable) for example. I did not want to overload its usage, so I opted to create a ClassNode instance with abstract modifier, Type as the super class, and Serializable as one interface. See getInferredTypeFromTempInfo -- this is the location where UnionTypeClassNode was being used to represent & relationship.

The duck-typing is in place for a UnionTypeClassNode. Thus 8965 (Deque and Stack peek) keeps working. I modified the switch case handling to collect types together in a union so the temp types list represents the and relationship and any element of the list may represent an or relationship (that is be an UnionTypeClassNode).

When processing a logical-or binary expression, temp types are collected for left and right sides. If an instanceof expression appears on either side, a (T | U) type is created and added to the temp type list. The logical-and binary expression remanins as before, adding any instanceof types from left or right expression directly to the temp type list as strong guarantees.

@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 82.55814% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.0155%. Comparing base (cc8bc3e) to head (f33e9b5).

Files with missing lines Patch % Lines
...roovy/transform/stc/StaticTypeCheckingVisitor.java 83.1169% 4 Missing and 9 partials ⚠️
...roovy/transform/stc/StaticTypeCheckingSupport.java 33.3333% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2353        +/-   ##
==================================================
+ Coverage     67.0080%   67.0155%   +0.0076%     
- Complexity      29357      29378        +21     
==================================================
  Files            1382       1382                
  Lines          116619     116667        +48     
  Branches        20444      20460        +16     
==================================================
+ Hits            78144      78185        +41     
+ Misses          32039      32037         -2     
- Partials         6436       6445         +9     
Files with missing lines Coverage Δ
...groovy/classgen/asm/sc/StaticTypesTypeChooser.java 100.0000% <100.0000%> (ø)
...haus/groovy/transform/stc/TypeCheckingContext.java 88.6364% <100.0000%> (+0.1306%) ⬆️
...ehaus/groovy/transform/stc/UnionTypeClassNode.java 39.3333% <100.0000%> (+3.1491%) ⬆️
...roovy/transform/stc/StaticTypeCheckingSupport.java 81.5013% <33.3333%> (ø)
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.6762% <83.1169%> (-0.0584%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants