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
Can yield do an implicit cast from dynamic under NNBD? #40538
Comments
It is working as specified, but the fact that downcasts under nnbd are only allowed from dynamic makes a difference: The cast from I agree that it appears inconsistent to make it an error to yield an expression of type We have a similar issue with The nnbd spec has the following:
I can't see any other rules about Note that this is very much about the ability to work with data structures whose "element type" is |
I agree that it should work. Inside an In any place where Dart 2.0 would do an implicit downcast from We might have cheated in the spec of the static type and said that |
We discussed this in December, and in the notes, we indicated that all of the following constructs are (and should continue to be) treated compositionally (by which I roughly mean that the downcasts should be done per-element): for-in, spreads, collection elements, and await. We noted that Example: Iterable<int> iterable() sync* {
Iterable<dynamic> d = <dynamic>[1];
yield* d;
}
void main() {
iterable(); // Currently fails with a cast error.
} cc @rakudrama |
It's only the One reason this is tricky is that An implementation could be A rewrite like So, we'd need a helper function which forwards valid values and errors, and which throws at the Keeping it illegal is the simplest option, and we can always make it better in the future. That argues against any rushes changes. So, if we keep So, let's not change |
Analyzer was updated to comply with the spec change. |
Bug: #40538 Change-Id: I9feaca0484f7a5c779068e823bbd765f5c06fe59 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136712 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Sad. Will the language spec change reverted? |
https://dart-review.googlesource.com/c/sdk/+/136814 will partially revert changes to analyzer, so that it continues checking using assignability of |
@scheglov thanks. Sorry for the wasted work. Yes, I think we'll want to do a similar partial revert on the spec changes. |
…pec decision. Bug: #40538 Change-Id: Idd563a15dc1e17e1271f823c33d015c73f720874 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136814 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sorry about the wasted work indeed. Spec changes required to make |
NNBD gets rid of implicit downcasts but, as I understand it, it still allows implicit casts from dynamic. My intuition is that yielding a value behaves the same as argument binding or assignment where an implicit cast from dynamic is allowed.
But if I take this:
And analyze it with:
I get:
@leafpetersen @lrhn @eernstg, is that working as intended? I'm tentatively assigning this as an analyzer bug with the assumption that a dynamic cast should be allowed here, but if not, feel free to close this.
The text was updated successfully, but these errors were encountered: