# Returning a FutureOr in an asynchronous function fails #32233

Closed
opened this issue Feb 19, 2018 · 1 comment

Member

### eernstg commented Feb 19, 2018 • edited

 Consider the following program: import 'dart:async'; FutureOr foo() => 42; Future bar() async => foo(); main() => bar(); The analyzer in strong mode responds as follows (when the program is stored in n020.dart): > dartanalyzer --version dartanalyzer version 2.0.0-dev.26.0 > dartanalyzer --strong n020.dart Analyzing n020.dart... error • The return type 'Future>' isn't a 'Future', as defined by the method 'bar' at n020.dart:5:28 • return_of_invalid_type 1 error found.  Presumably, this means that the returned expression in bar is checked in a manner which does not precisely correspond to the flatten function (from the language specification, sections Function Expressions and Return): If \code{$T =$ FutureOr<$S$>} then $flatten(T) = S$. ... It is a static type warning if the body of $f$ is marked \ASYNC{} and the type \code{Future<$flatten(T)$>} (\ref{functionExpressions}) may not be assigned to the declared return type of $f$.  But Future may be assigned to Future so the program should be accepted. Note that analysis of the same program succeeds with dartanalyzer --preview-dart-2.

### eernstg added area-analyzer analyzer-strong-mode labels Feb 19, 2018

referenced this issue Feb 19, 2018
Member

### leafpetersen commented Feb 20, 2018

 Probably related: #30638
pushed a commit that referenced this issue Jun 15, 2018
 Fix various bugs and regularize behavior of returns statements in 
various kinds of functions.

Closes-bug: #31887
Closes-bug: #30638
Closes-bug: #32233
Closes-bug: #32881
Closes-bug: #31278
Change-Id: I4ebd7e71096d611e189b571ba5de2998dd11c98b
Commit-Queue: Leaf Petersen <leafp@google.com>
 8e9e8e1