JDK-8016204 : Lambda Spec: Specify legal unchecked conversion in terms of inference
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-06-07
  • Updated: 2014-02-26
  • Resolved: 2013-10-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Relates :  
Description
In the 0.6.2 Lambda spec, a compatibility constraint (ArrayList -> List<alpha>) reduces to a subtyping constraint (ArrayList <: List<alpha>).  This does not allow for unchecked conversion (ArrayList <: List<alpha> reduces to false).  It is not sound to simply erase the supertype (ArrayList <: List), because there's not always a simple mapping from the type parameters of the subtype to the type parameters of the supertype.  Actual compiler behavior -- precisely when an unchecked conversion is allowed -- is poorly-defined.

Solution: Define legal unchecked conversions in terms of inference.  Introduce new inference variables when a raw type needs to be unchecked-converted (e.g., ArrayList<beta> <: List<alpha>), and include these variables in the enclosing context.
Comments
Since the proposed approach to unchecked conversion using inference may not be viable, that has been removed from the Lambda Spec. The following describes (soundly) the conditions under which unchecked conversion may be allowed during reduction: --- 18.2.2 Otherwise, if T is a parameterized type of the form G<T1, ..., Tn>, and there exists no type of the form G<S1, ..., Sn> that is a supertype of S, but the raw type G is a supertype of S, then the constraint reduces to true. Otherwise, if T is an array type of the form G<T1, ..., Tn>[]k, and there exists no type of the form G<S1, ..., Sn>[]k that is a supertype of S, but the raw type G[]k is a supertype of S, then the constraint reduces to true. (The notation []k indicates an array type of k dimensions.) Otherwise, the constraint reduces to ���S <: T���.
25-10-2013

JDK-7108313 discusses the possibility of changing unchecked conversions to happen _before_ rather than _after_ widening.
25-10-2013