pattern_type_mismatch_in_irrefutable_context
The matched value of type '{0}' isn't assignable to the required type '{1}'.
Description
#The analyzer produces this diagnostic when the type of the value on the right-hand side of a pattern assignment or pattern declaration doesn't match the type required by the pattern being used to match it.
Example
#The following code produces this diagnostic because x
might not be a
String
and hence might not match the object pattern:
dart
void f(Object x) {
var String(length: a) = x;
print(a);
}
Common fixes
#Change the code so that the type of the expression on the right-hand side matches the type required by the pattern:
dart
void f(String x) {
var String(length: a) = x;
print(a);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。