[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Inference of static types




> > > 1. What constraints will be added to the system for the cast or
> instanceof
> > > usage of a variable?
> 
> a = (Type) b;
> 
> This implies the 2 constraints:
> 
> T(b) >= Type 
> T(a) <= Type
> 
Thank you very much for your answers. It was not clear from the paper.

> > > Additionally, I probably found a defect in the algorithm:
> 
> There's no defect.  Let's look.
> 
> > >   public static void main(String[] args) {
> > >     Object b;
> > >     if (flag){
> > >       b = null;
> 
> T(b) <= T(null)
> 
> > >       use(b);
> 
> T(b) >= Integer
> 
> > >     }
> > >     else
> > >       b = new Boolean(true);
> 
> T(b) <= Boolean
> 
> > >
> > >     System.out.println(b);
> > >   }
> > > }
> 
You missed T(b)>=Object hear. So we have:

	Integer <= T(b) <= Boolean
     Object  <=       <=T(null)

So stage 1 will infer Boolean type as I mentioned in the previous letter.
Probably you do not add Object<=T(b) consraints to the system. If so I could
construct a sample with more depth in type hierarchy.


> So, T(b) is assigned Boolean.  
This is exactly what I thought. No matter in what stage we get this result,
:).

> Then "use" contraints are checked, and
> type casts are added if necessary.  Which would lead to:
> 
> use((Integer) b)
> 
Cast of Boolean to Integer is illegal in Java. So Boolean type for b
variable is NOT correct. The only correct type is Object. Am I wrong? 

Nikita