Currently if I write a function like below I'll get analyzer warning:--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.As I'm working on a Dart package which wraps JS client I needed to come up with a way to get this working.So I did this: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 email to analyzer-discuss+unsubscribe@dartlang.org.
Visit this group at https://groups.google.com/a/dartlang.org/group/analyzer-discuss/.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
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+uns...@dartlang.org.
@JS() external get undefined;
Function _createTransactionHandler<T>(TransactionHandler<T>
handler) {
return (currentData) { final data = dartify(currentData); final result = handler
(data); if (result._abort) return undefined; return jsify(result.data); }; }
Sorry about formatting issues, here is plain-text version of the same code snippet:@JS()external get undefined;Function _createTransactionHandler<T>(TransactionHandler<T> handler) {return (currentData) {final data = dartify(currentData);final result = handler(data);if (result._abort) return undefined;return jsify(result.data);};}
--
For more ways to connect visit https://www.dartlang.org/community
---
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+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2BeWuVBtfd%2BOh%2BumnEGDiGxd3HZ0%2Ba8_TcKzGidFX5WXLmOmxA%40mail.gmail.com.
Oh, just looked at my own example again. The problem is not in the _createTransactionHandler itself (which actually always returns Function) but in the closure created by this method.That closure must return an object representing the value, and null is a valid value in this case. To abort the transaction it must return undefined (in Dart semantics it must not return anything or in other words return void).
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAPe-b2Zj2yqMDyjO8RfvJUuDJ3gXEiR3dNnmrKzSPNkQxgyK2g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2BeWuVB3m_D0b1BQboLt2AMtxvGxbdWh-YeseNUHdGg4LA%2B9vA%40mail.gmail.com.