Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- 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:
- if (info != null) {
- if (info.elapsedTime != null) {
- if (info.elapsedTime > 0) { // same warning/error
- //...
- }
- }
- }
- But the following code does work:
- if (info != null) {
- var e = info.elapsedTime;
- if (e != null && e > 0) { // no warning/error
- //...
- }
- }
- Note that no warning or error is emitted at type check level 1.
Advertisement
Add Comment
Please, Sign In to add comment