Sdk: Analyzer hint for no return statement shouldn't apply to Null functions

Created on 7 Feb 2017  路  2Comments  路  Source: dart-lang/sdk

This code

Null returnsNothing() {
}

Causes a hint about no return statement. This seems unnecessary.

P2 analyzer-hint area-analyzer type-bug

Most helpful comment

Not to me.
A void function doesn't return anything. It can omit the return or use a return statement with no expression.
A non-void function returns something. It should use a return with an expression.

Trying to treat return; (or nothing) the same as return null; removes this distinction between a procedure/void function and an actual non-void function. Then you can argue that you should be able to use return; in all functions, as a shorthand for return null;, and I don't want that.

Basically I want return; and exit-with-no-return to act like an implicit return of type void, not of type Null.

What the current specification states is that it is a static warning for a return; in a synchronous, non-generator, non-generative-constructor function if the return type of the function isn't assignable to void (which means void or dynamic in Dart 1, probably just void in Dart 2).

All 2 comments

Not to me.
A void function doesn't return anything. It can omit the return or use a return statement with no expression.
A non-void function returns something. It should use a return with an expression.

Trying to treat return; (or nothing) the same as return null; removes this distinction between a procedure/void function and an actual non-void function. Then you can argue that you should be able to use return; in all functions, as a shorthand for return null;, and I don't want that.

Basically I want return; and exit-with-no-return to act like an implicit return of type void, not of type Null.

What the current specification states is that it is a static warning for a return; in a synchronous, non-generator, non-generative-constructor function if the return type of the function isn't assignable to void (which means void or dynamic in Dart 1, probably just void in Dart 2).

I agree, void has since become a very common/standard return type. I vote Analyzer should continue marking this as missing_return.

Was this page helpful?
0 / 5 - 0 ratings