Support type narrowing
It seems that this feature was implemented in the compiler in such a way that the data type of the type-narrowed symbol is unchanged. So we have to either change our strategy or change the way this is implemented in upstream.
Example:
class Derived : Object {
public void do_something () {
print ("hello\n");
}
}
void main() {
Object d = new Derived ();
if (d is Derived) {
d. // <-- we should expect `do_something()` in completions
}
}
Any feature the compiler supports should be supported in VLS, so this is a bug.
Or rather, not having this feature results in a behavior that's contrary to the behavior of the compiler, so that's why this is a bug and not an enhancement.
@Prince781 The value_type of a MemberAccess provides you with an optional context_symbol which should be used, if set, as replacement for type_symbol.
There's a couple of problems with implementing this as things stand:
- The
SymbolExtractorhas to be modified to setcontext_symbolwhen resolving the type of an expression. We rely on the symbol extractor for most completions because it's much faster than a full parse. However, if the extractor must reimplement the work of narrowing the type, we could just setvalue_typeinstead. - I think this is something more appropriate for the compiler to do, since this requires flow analysis for types.