bug: vscode extension warns about possible nulls where it's not possible
Why I get this yellow wave line under the comparsion? I thought this was already fixed long ago (though that might have been in the compiler, not the vsc extension)
Type narrowing doesn't work for non-local variables. If you rewrite the code with intermediate local variables, then it works as expected.
I understand the limitation here - it's similar to why types can only be inferred for local variables: because the compiler can't always know that you aren't assigning some value to a global or member variable that reset its idea of what the type is.
But I would argue that the compiler can and should be smarter in cases like the examples you have given.
Type narrowing doesn't work for non-local variables. If you rewrite the code with intermediate local variables, then it works as expected.
I understand the limitation here - it's similar to why types can only be inferred for local variables: because the compiler can't always know that you aren't assigning some value to a global or member variable that reset its idea of what the type is.
But I would argue that the compiler can and should be smarter in cases like the examples you have given.