Skip to content

Conversation

@isaric
Copy link
Contributor

@isaric isaric commented Dec 30, 2025

Summary

Fixes incorrect assignability checks for parameterized types with nested generic arguments.

Problem

TypeUtils.isAssignable() incorrectly returned true when checking if MyComparator<Iterable<MyNonTransientException>> is assignable to MyComparator<? super MyNonTransientException>. This happened because the type variable unrolling logic in getTypeArguments() didn't properly resolve nested generic arguments when traversing the inheritance hierarchy.

Changes

  • Enhanced getTypeArguments(): When walking up the inheritance hierarchy, now properly unrolls type variables in parameterized parent types before recursing, ensuring nested generic arguments are correctly resolved
  • Fixed infinite recursion in unrollVariables(): Added a visited set to track already-visited TypeVariable instances, preventing infinite loops when circular type variable references exist
  • Fixed in-place mutation: Now clones type argument arrays before modifying them to avoid unintended side effects
  • Added test coverage: New test_LANG_1700() validates the fix with a complex parameterized type hierarchy

Test Case

The test verifies that LexOrdering<MyNonTransientException> (which implements MyComparator<Iterable<MyNonTransientException>>) is correctly identified as not assignable to MyComparator<? super MyNonTransientException>, since Iterable<MyNonTransientException> is not a supertype of MyNonTransientException.

@isaric
Copy link
Contributor Author

isaric commented Dec 30, 2025

Linked PR
#1548

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @isaric

Please rebase on git master to pick the latest changes, including your other PR.

Thank you!

Enhanced `TypeUtils` to correctly handle parameterized types with nested generic arguments and improve unrolling of type variables. Updated `unrollVariables` to prevent infinite recursion by handling visited `TypeVariable` instances. Modified argument cloning to avoid in-place mutations. Added unit tests to validate behavior against complex parameterized types and ensure accurate assignability checks.
@isaric isaric force-pushed the LANG-1700-parametrized-type branch from abae510 to 5562fc3 Compare December 31, 2025 20:37
@isaric isaric requested a review from garydgregory December 31, 2025 21:11
@isaric
Copy link
Contributor Author

isaric commented Dec 31, 2025

@garydgregory You're welcome! Rebased off master.

@garydgregory garydgregory changed the title LANG-1700 Improve handling of parameterized types and variable unrolling [LANG-1700] Improve handling of parameterized types and variable unrolling Dec 31, 2025
@garydgregory garydgregory merged commit 8f8cc04 into apache:master Dec 31, 2025
35 of 36 checks passed
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