Use wildcards for least upper bound of two lists #286
Labels
Component: code generation
Something that concerns the generated code
Component: DSL
Something that concerns the design of PIE DSL
Priority: medium
Status: specified
Enhancement that is ready to implement
Type: bug
Something isn't working
Type: enhancement
New feature or request
Summary
Use a list of upperbounded wildcard as least upper bound for two lists:
val res: (_ <: Fruit)* = if(flag) apples else bananas
Todo
Reason
It currently uses a list of toptype, but that is less precise than a list of an upperbounded wildcard.
It may actually be incorrect tooIt is also incorrect:if(true) [0] else ["zero"]
generates invalid Java code, as it tries to make the assignmentArrayList<Object> obj = ArrayList<Integer>
Description
In case the least upper bound of the element types is toptype,
just use a list of toptype (as it does now) instead of a list of a wildcard upperbounded by toptype, if that is possible (see possible incorrectness in reason above).just use a list of wildcards instead:ArrayList<?>
Implementation
Least upper bound of
X*
andY*
becomes(_ <: lub(X, Y))*
, unlesslub(X, Y) == TopType()
, then it becomes(_)*
Related issues
None?
The text was updated successfully, but these errors were encountered: