-
Bug
-
Resolution: Unresolved
-
P3
-
8, 9
Longstanding inference behavior of javac (in releases 5-8) is to avoid upper/lower bounds that mention inference variables by, instead, mapping those variables to their bounds during reduction. This leads to various unspecified failures and has been addressed—see JDK-8033718 and JDK-8039214.
javac's interest in avoiding capture variables is reasonable, though. Various programs that used to compile no longer will after the fix—seeJDK-8075793. While we've reverted to the old behavior under "-source 7" and previous, going forward it makes sense to try to infer types that are not capture variables when possible.
Proposed reconciliation of spec and implementation: Follow JLS on reduction. During resolution, if the lower bound that would produce the instantiation is a capture variable, try using the variable's upper bound instead; and if the upper bound that would produce the instantiation is a capture variable, try using the variable's lower bound (if any) instead. If the attempt fails, revert to the capture variable.
A more powerful, and maybe more consistent, approach is to use upward and downward projection here, as in JDK-8016196.
javac's interest in avoiding capture variables is reasonable, though. Various programs that used to compile no longer will after the fix—see
Proposed reconciliation of spec and implementation: Follow JLS on reduction. During resolution, if the lower bound that would produce the instantiation is a capture variable, try using the variable's upper bound instead; and if the upper bound that would produce the instantiation is a capture variable, try using the variable's lower bound (if any) instead. If the attempt fails, revert to the capture variable.
A more powerful, and maybe more consistent, approach is to use upward and downward projection here, as in JDK-8016196.
- relates to
-
JDK-8016196 Inference: define supertype parameterization for wildcard-parameterized types
- Open
-
JDK-8033718 Inference ignores capture variable as upper bound
- Closed
-
JDK-8039214 Inference should not map capture variables to their upper bounds
- Closed
-
JDK-8075793 Source incompatibility for inference using -source 7
- Closed