"Self" type arguments lead to confusing error messages #52204
Labels
legacy-area-front-end
Legacy: Use area-dart-model instead.
model-messages
Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.
Sometimes you need a class which will have subtypes but you need the "Self" type, e.g. so you can have an API that always talks in terms of the same object. One way to do that is to have the superclass have a type argument defined like this:
Now subclasses have to specify themselves as the type argument:
If they don't specify any type, they get an error:
Other classes can use this abstract type as a generic type argument:
...and type inference works fine:
Sometimes, though, there isn't anything in the equivalent of
Baz
to help the type inference; e.g.:I guess I don't know what I would propose instead. I don't know if we can reliably detect this kind of situation but it would be nice to have a message like:
(I suppose maybe this is really just a long-winded argument for us introducing an explicit
Self
type...)The text was updated successfully, but these errors were encountered: