-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"is" operator inconsistent with type coercion for member variables #21530
Comments
Added Area-Language, Triaged labels. |
Removed Type-Defect label. |
The problem with allowing |
This comment was originally written by [email protected] That is a good point and another fair argument in favor of Issue #5031 as the pattern would remain consistent across all usages. ex: Foo foo = x as Foo; // <-- not possible with throw :( Currently 'as' is basically useless at this point and actually could introduce a bug in the implicit / non-implicit scenario you have described. consider: if(x is Foo) With the current generic warning generated from the 'is' block with member usage; a programmer could very well think the above approach would fix the problem, but would yield a similar result as the bug you described. In the end I would prefer casting to be more explicit regardless. There are valid situations when they are handy and necessary, but the programmer should pretty much always be cognizant of the usage and possible side effects. What if, for example, the user actually intends to call fooMethod on the current member and not a local variable as they know that bar may change said member. Maybe removing the reference was an intended side effect of 'destroying' the previous object. The programmer would need to do another cast regardless in this case (any casting pattern will do): if(x is Foo) In the end casting is an explicit act and would preferably be used in that way. I would think at least 1 of two resolutions could improve the situation a bit.
|
Duplicate of #34480 which, while opened later, has more discussion and examples. |
This issue was originally filed by [email protected]
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Expected: Dart should coerce the member as it does with local variables and function parameters.
Actual result: Dart editor produces an error and requires an explicit cast to use the type.
What version of the product are you using?
Dart 1.6.0
On what operating system?
Mac OSX
What browser (if applicable)?
N/A
Please provide any additional information below.
I would actually prefer Issue #5031 be addressed then an implicit coercion be used, but since the implicit coercion appears to be the preferred method in Dart it should be consistent.
The text was updated successfully, but these errors were encountered: