Skip to content
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

doc: Add a warning about de-structuring Maps with a key that doesn't exist in that map throwing a StateError #6320

Open
1 task done
exaby73 opened this issue Jan 10, 2025 · 0 comments · May be fixed by #6321
Open
1 task done
Labels
from.page-issue Reported in a reader-filed concern

Comments

@exaby73
Copy link

exaby73 commented Jan 10, 2025

Page URL

https://dart.dev/language/pattern-types#map

Page source

No response

Describe the problem

Consider the following code:

void main() {
  final {'foo': int? foo} = {};
  print(foo);
}

This causes a StateError to be thrown as you can't match a key that doesn't exist in the map. We should document this behavior as it's not mentioned anywhere

Expected fix

Add a warning about this behavior on https://dart.dev/language/pattern-types#map

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on dart.dev.
@exaby73 exaby73 added the from.page-issue Reported in a reader-filed concern label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from.page-issue Reported in a reader-filed concern
Projects
None yet
1 participant