-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FutureOr<void> function warns of missing return #35237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Actually, I don't get any warnings if I change the return type to just |
The feature specification 'invalid_returns.md' does not make it explicit in which cases it is allowed to complete the body of a function normally (that is, to "fall through" at the end), and it allows only I can't confirm this from the text of the language specification, but it would be a reasonable rule to say that Basically, With the given information about the broader context, it sounds to me like |
So is it valid to override a I expected that the override would have to declare the exact same type, but certainly this seems to work in my tests (assuming my tests correctly cover this 🤷♂️). |
And a slight tangent, I guess the same question applies to arguments... If I use abstract class Foo<T> {
doFoo(T thing);
}
class Bar extends Foo<void> {
doFoo(void _) {
// Is `void _` the best option here?
}
} |
Right, return type The type Overriding return type In general, Dart has covariant return types, that is, return type
I think Of course, having an parameter of type |
Yeah, I didn't set out to use it, it just was a consequence of some generics. I have a base class for some handlers - some will return values and some will not. It feels clumsy making all those that do not
Cool :) It's similar to the above - my generic handler has a type arg for the parameter type, but one of the methods doesn't take the arg so I use void. Unfortunately calling it isn't quite so simple, because it doesn't seem valid to pass abstract class Foo<T> {
doFoo(T thing);
}
class Bar extends Foo<void> {
doFoo(void _) {}
}
test() {
final a = new Bar();
a.doFoo(); // invalid
a.doFoo(void); // invalid
a.doFoo(null); // valid?;
} It feels dirty passing It seems like there's probably nothing to do here, so unless you think there's something that can/should be improved, feel free to close this. Thanks for the info! |
The overriding declaration is allowed to make the argument optional:
Will do, and thank you! |
With the following code:
The second function gives a hint about a missing return:
It's not entirely obvious what I should do - it's not valid to write
return void
and I can't change the signature because it comes from a base class (thevoid
is a type arg and has a real type for other implementations). It doesn't complain if I writereturn null
though it feels weird (and I've not got as far as running it to confirm that's ok yet).The text was updated successfully, but these errors were encountered: