Open
Description
I would like to get a lint warning/hint for ternary operators when encountering code like this:
A -> SubClass1 -> BaseClass, with Element -> Object
B -> SubClass2 -> BaseClass, with Element -> Object
var shouldBeOfTypeBaseClass = someBoolCheck() ? new A() : new B();
// the analyzer will infer that shouldBeOfTypeBaseClass is of type Object instead of the
// desired `BaseClass` class
// the same thing would apply to the ?? operator
A a;
B b = new B();
var shouldBeOfTypeBaseClass = a ?? b;
See #30079 (comment) for more info on motivation.
I'd like to see a lint warning on the var
before shouldBeOfTypeBaseClass
pointing out that the type of shouldBeOfTypeBaseClass
will be inferred as Object and you should specify a base class type instead of using var.