Guest User

thanksgarmin

a guest
Jan 8th, 2025
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. Given that the code you posted produces that exact compile warning/error in both the latest stable SDK [7.4.3] and the latest beta [8.0.0-beta], at type check levels 2 and 3, I'd say the problem isn't in the extension but rather in the compiler.
  2.  
  3. The [long-standing] problem here is that this kind of type narrowing only seems to work with local variables. Rewriting your code as the equivalent nested conditional doesn't work:
  4.  
  5. if (info != null) {
  6. if (info.elapsedTime != null) {
  7. if (info.elapsedTime > 0) { // same warning/error
  8. //...
  9. }
  10. }
  11. }
  12.  
  13. But the following code does work:
  14. if (info != null) {
  15. var e = info.elapsedTime;
  16. if (e != null && e > 0) { // no warning/error
  17. //...
  18. }
  19. }
  20.  
  21. Note that no warning or error is emitted at type check level 1.
Advertisement
Add Comment
Please, Sign In to add comment