Ejemplo n.º 1
0
 private void computeDeferredTypes() {
   Collection<Box<DeferredType>> deferredTypes = trace.getKeys(DEFERRED_TYPE);
   if (deferredTypes.isEmpty()) {
     return;
   }
   // +1 is a work around against new Queue(0).addLast(...) bug // stepan.koltsov@ 2011-11-21
   final Queue<DeferredType> queue = new Queue<DeferredType>(deferredTypes.size() + 1);
   trace.addHandler(
       DEFERRED_TYPE,
       new ObservableBindingTrace.RecordHandler<Box<DeferredType>, Boolean>() {
         @Override
         public void handleRecord(
             WritableSlice<Box<DeferredType>, Boolean> deferredTypeKeyDeferredTypeWritableSlice,
             Box<DeferredType> key,
             Boolean value) {
           queue.addLast(key.getData());
         }
       });
   for (Box<DeferredType> deferredType : deferredTypes) {
     queue.addLast(deferredType.getData());
   }
   while (!queue.isEmpty()) {
     DeferredType deferredType = queue.pullFirst();
     if (!deferredType.isComputed()) {
       try {
         deferredType.getDelegate(); // to compute
       } catch (ReenteringLazyValueComputationException e) {
         // A problem should be reported while computing the type
       }
     }
   }
 }
Ejemplo n.º 2
0
 private static void computeDeferredType(JetType type) {
   // handle type inference loop: function or property body contains a reference to itself
   // fun f() = { f() }
   // val x = x
   // type resolution must be started before body resolution
   if (type instanceof DeferredType) {
     DeferredType deferredType = (DeferredType) type;
     if (!deferredType.isComputed()) {
       deferredType.getDelegate();
     }
   }
 }