-
Notifications
You must be signed in to change notification settings - Fork 1.7k
null is not legal from Map<String, Object> from analyzer #48477
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
Comments
Using IntelliJ with Dart 2.16 I do not understand the behavior of the following:
This is not reported as an error. However, I thought the return value was null if the Map did not contain the key ??? Not a problem for me, as I just changed the code to
If this really is an error I will generate and test code that exhibits the behavior. |
I do get a warning about Is your project using language version Dart 2.12 or later, by setting the SDK version to If not, then your code is still being compiled as pre-Null Safety code. |
I am using the null safe version of the compiler. I use ! and late etc without problems. |
Made a transcription mistake. I used Here is the short example that I checked.
|
That explains it. Doing So, it's all because of an implicit |
I would expect that t=null would not be allowed because t is of type Object and not The type of B for Map<A,B> does not matter for type safety when accessing the result of a map. The type of the result is always nullable. Well I can see why a runtime check could be used, but in this case there is a clear You answered my question, so thank you for your help. |
I found this issue mentioned earlier as part of open issue #1324
"If null safety is about the compiler catching possible null assignments, then dynamic spoils this." So this "new" issue should be closed. Thank you again for your help. |
The type Example: Map<String, dynamic> map = <String, String>{"x": "a string"};
int number = map["x"]; // No warning, guaranteed run-time error. Heck, even int x = "not an int" as dynamic; will compiler fine and throw at runtime. That's what |
No description provided.
The text was updated successfully, but these errors were encountered: