-
Notifications
You must be signed in to change notification settings - Fork 213
The property type is not checked when I use ?? operator to set a value #2257
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
The problem here is indeed Fwiw typing the map as Or you can more generally enable this in your analysis_options.yaml file, which I would also highly recommend: analyzer:
language:
strict-casts: true |
Thanks for answer @jakemac53 ! I didn't knew the 'strict-casts' option. It's really cool! 😁 I think would be a nice feature because It's really common see the people use this pattern around the projects. But it's just a suggestion anyway 🙂 |
Yeah, I definitely see how that is confusing. Afaik the reason this isn't caught is because it is only the type of the entire expression that is checked against the LHS. That type is the least upper bound of I think to catch this type of problem would require pushing that lhs type "down" into the expression which would presumably be a large change to how the type system works today (and it probably isn't done that way for other, good reasons?). But maybe somebody else can chime in to that effect, I am not a type system guy haha.
|
It's not terribly complex, but it would likely be a reasonably substantial breaking change. This is currently tracked as a part of a larger set of related changes that we might consider making here. cc @stereotype441 I'm going to close this issue in favor of that issue unless there is something specific we want to track here. |
Hello guys! I don't know if it's a intentional behavior, but for me it's so strange that I think that's a bug.
Basically the property "total" is a double, but in the fromMap method I'm able to set a empty string if map['total'] is null. This probably works at compile-time because the "map" has dynamic subtypes, but since I'm using the null checker I think the right behavior is the compiler doesn't allow the string be defined in case of the value being null.
And yes, at runtime it's breaks.
The text was updated successfully, but these errors were encountered: