[Checkers] More Generics complications

Mahmood Ali mahmood at MIT.EDU
Sat Apr 19 01:54:58 EDT 2008


Hi guys,

I am planning to work on AnnotatedTypeFactory.unify() and make it use  
annoRelations.  unify() is called for finding the least upper bound on  
conditional expressions.  I just realized that unifying annotations on  
the raw type is different from unifying ones on type argument.  On raw  
type, one need to take the super (least restrictive) annotation, while  
on type arguments it is complicated.

Examples:
Raw types:
   (true ? {@NonNull String} : {@Nullable String>}  --> {@Nullable  
String}     // Nullable is least restrictive here!
   (true ? {@NonNull List<@NonNull String>} : {@Nullable List<@NonNull  
String}  --> {@Nullable List<@NonNull String}  // Nullable is least  
restrictive here!

Type Arguments:
   (true ? {@NonNull List<@NonNull String>} : {@NonNull List<@Nullable  
String>}  --> cannot really unify the types

Reason:
- The iterator may have null elements, if the false expression is  
returned
- one cannot add a null item to resulting list, if the true expression  
is returned

What do you think we should do?  We may want to include it in the  
paper.  This may be the second item we have regarding generics.  Given  
that none of the other type systems handle generics, it might be  
worthy to write a section regarding the difficulties with it.

For now, maybe we can simply issue a warning whenever the types of the  
true expressions and false expressions are distinct un-unifiable types.

Regards,
Mahmood

P.S. sorry for not being clear. need to get some sleep!



More information about the checkers mailing list