You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The analyzer shows a warning when a pattern matches an extension type saying that the value will never match the required type, when it clearly will.
The following dart code contains some examples and the corresponding analyzer warnings that are shown.
extension typeconstId(int i) {}
classFoo {
constFoo(this.id, this.ids);
finalId id;
finalList<Id> ids;
}
voidmain() {
const foo =Foo(Id(0), [Id(1), Id(2)]);
switch (constId(0)) {
caseId():// ^^ The matched value type 'Id' can never match the required type 'Id'.print('id');
}
switch (foo) {
caseFoo(:final id):// ^^^^^^^^ The matched value type 'Id' can never match the required type 'Id'.print(id);
}
switch (foo) {
caseFoo(:final ids):// ^^^^^^^^^ The matched value type 'List<Id>' can never match the required type 'List<Id>'.print(ids);
}
}
When switching the extension type with a corresponding class, the warnings disappear.
The program executes as expected and the cases are matched.
This happens in Dart SDK version: 3.3.0 (stable) as well as on the current master channel on dartpad.