'Brian Wilkerson' via Dart Misc
2018-03-08 15:36:45 UTC
Moved discussion to '***@dartlang.org'.
On Wed, Mar 7, 2018 at 11:24 PM, Anatoly Pulyaevskiy <
On Wed, Mar 7, 2018 at 11:24 PM, Anatoly Pulyaevskiy <
myFunc() {
if (isSomething) return;
return "some value";
}
Analyzer warning: Functions can't include return statements both with and
without values.
As we know in JS this is not an issue and sometimes is even used as a
feature. Which is the case with Firebase Database JS client.
(example: https://firebase.google.com/docs/reference/js/
firebase.database.Reference#transaction)
As I'm working on a Dart package which wraps JS client I needed to come up
with a way to get this working.
Function _createTransactionHandler<T>(TransactionHandler<T> handler) {
// This is a workaround for analyzer which complains if a function
contains
// return statements with and without value.
void undefined() {}
// Firebase requires us to return JS `undefined` to indicate we want
// to abort the transaction.
return (currentData) {
final data = dartify(currentData);
final result = handler(data);
if (result._abort) return undefined(); // workaround continues...
return jsify(result.data);
};
}
Which works (with latest Dart2 SDK, 2.0.0-dev.32.0). But I was wondering
if there is any plans in Dart2 to statically restrict this kind of usage?
My gut feeling says that since `void` in Dart2 is more like a value of
special type (we can use it in generics like Future<void>) then my
workaround should be statically allowed, but I just wanted to confirm it
with the team.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/a/
dartlang.org/group/analyzer-discuss/.
if (isSomething) return;
return "some value";
}
Analyzer warning: Functions can't include return statements both with and
without values.
As we know in JS this is not an issue and sometimes is even used as a
feature. Which is the case with Firebase Database JS client.
(example: https://firebase.google.com/docs/reference/js/
firebase.database.Reference#transaction)
As I'm working on a Dart package which wraps JS client I needed to come up
with a way to get this working.
Function _createTransactionHandler<T>(TransactionHandler<T> handler) {
// This is a workaround for analyzer which complains if a function
contains
// return statements with and without value.
void undefined() {}
// Firebase requires us to return JS `undefined` to indicate we want
// to abort the transaction.
return (currentData) {
final data = dartify(currentData);
final result = handler(data);
if (result._abort) return undefined(); // workaround continues...
return jsify(result.data);
};
}
Which works (with latest Dart2 SDK, 2.0.0-dev.32.0). But I was wondering
if there is any plans in Dart2 to statically restrict this kind of usage?
My gut feeling says that since `void` in Dart2 is more like a value of
special type (we can use it in generics like Future<void>) then my
workaround should be statically allowed, but I just wanted to confirm it
with the team.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/a/
dartlang.org/group/analyzer-discuss/.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.