tighten_type_of_initializing_formals
Use a type annotation rather than 'assert' to enforce non-nullability.
Description
#The analyzer produces this diagnostic when an assert
is being used in
the initializer list of a constructor to ensure that only a non-null
value is being used to initialize a field.
Example
#The following code produces this diagnostic because an assert
is being
used to catch an error that could be caught by the type system:
dart
class C {
final String? s;
C(this.s) : assert(s != null);
}
Common fixes
#Remove the assert
and add the non-nullable type before the initializing
formal:
dart
class C {
final String? s;
C(String this.s);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。