Repository navigation
Description
This is a meta-issue for a constraint solver rewrite for generic method inference to encompass #1585 and #1291. Right now, our solve() method to solve constraints has signature:
This needs to change in (at least) two ways:
- The returned
Mapis currently key'd onElements corresponding to generic type variables. But as shown in Generic method inference does not support inferring different nullability for multiple calls to same generic method #1291, the same generic method may be invoked more than once in the context of a particular inference problem. So, really this should be key'd on somerecorddatatype that includes both theElementand also theMethodInvocationTreeidentifying the call to the generic method. - Enhance generic method inference to compute mappings from type variables to full types? #1585 discusses how in various cases it would be better to infer a complete nullness-annotated type for each value in the map. Right now the values are
InferredNullability, which only gives the top-level nullability of a type. Instead, the values in the map should be fully nullness-annotatedTypes, including nested annotations.
This may require other changes to the solver interface, e.g., addSubtypeConstraint may also need a MethodInvocationTree parameter to identify which call generated the constraint.
Clearly the internal vars map in ConstraintSolverImpl would have to change to track all this additional information. It too would also need to incorporate invocation trees into its keys and fully-annotated types into its values.
My hope is that with a fix here for #1585 we can remove some or all of the hacks from #1473 and #1574; I would hope that the entire NestedTypeVarSubstitutionRepairVisitor type and its related "repair" code could just go away.
Beyond keeping existing tests passing, the new test cases in #1291 and #1585 should also pass after the rewrite.
Activity
msridhar commentedon Oct 7, 2026
FYI @subhramit
subhramit commentedon Oct 7, 2026
Commenting to allow assignment
subhramit commentedon Oct 9, 2026
vlsi commentedon Oct 9, 2026
Another case for the rewrite: #1947. In
List.copyOf(new ArrayList<>(list))with aList<T>whoseTadmits null, the inner call's type variable is itself under inference, so the constraint #1834 adds for the directList.copyOf(list)never seesT's nullable bound. With full inferred types (#1585) the inner variable would be inferred asT.Use call-specific generic inference variables (#1965)
subhramit commentedon Oct 19, 2026
Preserve nullability of intersection bounds (apache#1972)