Analyzer allows accessing statics/members on type aliases alising a type variable. #52812
Labels
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
dart-model-analyzer-spec
Issues with the analyzer's implementation of the language spec
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Dart allows accessing static members and constructors of classes (class/mixin/enum declarations) through type aliases, but only if the type alias doesn't "expand to a type variable" (and then only if it explicitly denotes a class.)
A type alias expands to a type variable if its RHS is a type variable, or it's
Q<TypeArgsOpt>
whereQ
is a (possibly qualified) identifier denoting a type alias which expands to a type variable.(We don't care what the type arguments are, we just follow the name at the head of the type until a non-type-alias is found.)
So a type alias explicitly denotes a non-alias declaration
C
if its RHS is= Q<TypeArgsOpt>;
whereQ
is an identifier or qualified identifier directly denotingC
, or transitively ifQ
denotes another type alias declaration which then explicitly denotesC
.Further, accessing statics on instantiated type expressions (
Q<TypeArgs>
) is always an error. IfQ<TypeArgs>
is a type expression, then the only continuations are constructor tear-offs or invocations,(args)
,.new(args)
,.name(args)
,.new
, or.name
. Any other follow-up selector is a compile-time error.Which means you can't do
typedef A<T> = T; A<int>.parse("1");
for two reasons:parse
is not a constructor, so it can't be invoked on an instantiated type expression at all, andA
doesn't denote a class.Example:
The front end gives the following errors (from dartpad.dev).:
which is one error per place the term
A<C>
is used as receiver for a member access, and one whereC2<int>
is used.(Plus two spurious errors where it seems to try doing the access on a
Type
object instead, which shouldn't happen.)The analyzer gives only one error:
(and one info, saying that the extension method
inst
isn't used, which is doubly weird).Something is going wrong with errors about accessing members through type aliases which expands to a type variable.
The analyzer correctly recognizes that
C2<int>.stat
is not allowed, but not thatA<C>.stat
is not allowed for the same reason, and for another reason too.The text was updated successfully, but these errors were encountered: