Future/FutureOr require returns?

The following triggers an analysis warning in 2.0.0-dev.32.0:

import 'dart:async';

void returnNothing() {
  return; // OK
}

Future<void> returnNothingInTheFuture() async {
  return; // ERROR: Expecting return.
}

FutureOr<void> returnNothingMaybeInTheFuture() async {
  return; // ERROR: Expecting return.
}

I can silence it with return null; … but can’t that be automatic?

Author: Fantashit

1 thought on “Future/FutureOr require returns?

  1. The current situation is clearly just wrong:

    import 'dart:async';
    
    void foo1() {
      return;
    }
    
    Null foo2() {
      return;
    }
    
    Future<void> foo3() async {
      return; // warning • Missing return value after 'return' at test.dart:12:3 • return_without_value                                                                                                                                                            
    }
    
    Future<Null> foo4() async {
      return;
    }
    
    void main() { }

Comments are closed.