dart-archive / dart2_fix

A tool to migrate API usage to Dart 2
https://pub.dartlang.org/packages/dart2_fix
BSD 3-Clause "New" or "Revised" License
7 stars 3 forks source link

specified main()'s return type #31

Closed bcko closed 6 years ago

bcko commented 6 years ago

https://www.dartlang.org/guides/language/language-tour#the-main-function

devoncarew commented 6 years ago

And, you likely need an import 'dart:async'; now (https://travis-ci.org/dart-lang/dart2_fix/builds/383416131#L572), to reference the Future.

bcko commented 6 years ago

Thank you for your help! :)

devoncarew commented 6 years ago

Thanks!

eernstg commented 6 years ago

Forgive me for commenting on an already closed PR, but here's a bit of information that may be useful in similar situations:

The language team actually decided to allow an async method to have the return type void, and the motivation is that this is a meaningful representation of the intent that invocations of that function should be a "fire and forget" operation: Callers should discard the returned future, and this means that they can't even synchronize on the completion of the associated task.

Considering an async main, we actually have a good match for this description. The specification says nothing about how the returned value is used, and there is no support for claiming that the returned value is not ignored.

This means that we could make the case that void main() async {...} is fine, and in the concrete context of this PR it also allows us to avoid an import.

PS: This is new, so the available tools may or may not have the feature implemented in any given context.

devoncarew commented 6 years ago

Awesome, thanks for the context and explanation @eernstg!