Commit Graph

3 Commits

Author SHA1 Message Date
Kevin Millikin 9bdf2489b5 Signal errors and warnings for invalid returns
Implement the feature spec for checking returns against inferred
function return types:

https://github.com/dart-lang/sdk/blob/master/docs/language/informal/invalid_returns.md

with the change that an invalid return without a subexpression is
a warning, not an error.  This is because it is a warning in the
analyzer and it would be a breaking change to turn it into an
error.

The check for valid returns is moved to exactly where we handle
returns, rather than in ensureAssignable which is used as a
helper in a lot of places. A bug in type inference was fixed: we
would use `void` for the type of return without a subexpression
instead of `null`.  To accommodate that we would use a
non-standard subtyping relation for returns.  This could lead to
us inferring a return type of `void` in cases where we should
not.

Change-Id: Iee9ece9c722f47efa305f49490d3022d0bbb9f44
Reviewed-on: https://dart-review.googlesource.com/72403
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2018-09-04 16:50:51 +00:00
Paul Berry b75502513a Fix type inference of closures using '=>' syntax.
This CL fixes type inference of closures using '=>' syntax so that
they infer consistently with an equivalent closure defined using block
syntax ('{}').

Fixes #31436.

Change-Id: I5463dd0ba986e9953ebabbc24ce3ced9a7220007
Reviewed-on: https://dart-review.googlesource.com/27084
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-12-07 04:52:10 +00:00
Paul Berry 28ed82075e Fix a type inference corner case: return expression where void expected.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2888073003 .
2017-05-17 10:01:18 -07:00