You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
List<(int, int)> vals = [];
for (var (a, b) in vals) {
print(a+b);
}
but this fails with error The argument type 'InvalidType Function(dynamic Function(int, int))' can't be assigned to the parameter type 'dynamic Function((int, int))':
List<(int, int)> vals = [];
final sums = vals.map(((int a, int b)) => a + b).toList(); // Error
I assumed destructuring should work in lambda parameters.
Actually it doesn't work even in function definitions -- this fails with a very strange syntax error, Use the generic function type syntax to declare the parameter ''. Try using the generic function type syntax.
voidsum((int a, int b)) => a + b; // Error
The following works (by not using destructuring at all). You can't use v.a or v.b, since the field names are ignored in the type:
voidsum((int a, int b) v) => v.$1 + v.$2;
The text was updated successfully, but these errors were encountered:
is there an issue for allowing v.a and v.b to be used instead of v.$1 and v.$2, in the last example I gave?
I don't think so. Please file it at dart-lang/language repo (that's the place for all language feature requests).
The choice of names not having any meaning was deliberate, but I don't see any reason why it would not work to just allow this in a statically typed context (i.e. ignoring dynamic invocations entirely).
This works:
but this fails with error
The argument type 'InvalidType Function(dynamic Function(int, int))' can't be assigned to the parameter type 'dynamic Function((int, int))'
:I assumed destructuring should work in lambda parameters.
Actually it doesn't work even in function definitions -- this fails with a very strange syntax error,
Use the generic function type syntax to declare the parameter ''. Try using the generic function type syntax.
The following works (by not using destructuring at all). You can't use
v.a
orv.b
, since the field names are ignored in the type:The text was updated successfully, but these errors were encountered: