This was more surprising than anything while migrating existing code.
(I was able to change it to foo != null to unblock myself, but more an FYI for the team to review)
Working as intended.
The only checks which promote are is/as and == null/!= null checks.
There is no promotion using identical(foo, null). There is no need for it since == null does exactly the same thing, and that's the preferred way to write it.
Should there be a hint that identical(foo, null) is never what you want to write?
CC @bwilkerson @scheglov @pq RE a hint. Agree it's a good idea!
I changed the title to make it clear this is a feature request not a bug. The existing spec is thus irrelevant.
@stereotype441 WDYT? This doesn't seem super high value, but if it's fairly trivial to support, we might consider trying to slip it in as a post-beta/pre-stable fix?
@stereotype441 WDYT? This doesn't seem super high value, but if it's fairly trivial to support, we might consider trying to slip it in as a post-beta/pre-stable fix?
It's easy going to be super-easy or it won't; it all depends on whether the resolution of the identical is available at the time that it's needed by flow analysis. I'll go ahead and add it to my list to work on this in the post-beta timeframe, and if it's trivial I'll go ahead and do it.
FWIW, having filed this issue - I don't think it's that important - https://github.com/dart-lang/language/issues/1226#issuecomment-693034800 is more important to me as a resolution
FYI @bwilkerson @pq regarding the idea of a hint (https://github.com/dart-lang/language/issues/1226#issuecomment-693034800)
It sounds reasonable to me but @bwilkerson has been thinking about these kinds of hints more recently so I'd love his input. Needless to say, happy to implement if it's a go.
We require that hints have zero false positives, and it isn't clear to me that it's aways wrong (as opposed to just suboptimal) to use identical to compare to null, even if we were to limit that to conditions where promotion would otherwise have occurred.
I wouldn't have any problem making it a lint.
Most helpful comment
Should there be a hint that
identical(foo, null)is never what you want to write?