Use dart analyze package for num.clamp (#139867)

Extacted from #130101, dropped the `@_debugAssert` stuff from that PR so it's easier to review.
This commit is contained in:
LongCatIsLooong
2023-12-11 12:25:26 -08:00
committed by GitHub
parent 44beb843aa
commit aa609127e7
21 changed files with 283 additions and 98 deletions

View File

@@ -19,3 +19,33 @@ class Foo {
/// Simply avoid this
/// and simply do that.
class ClassWithAClampMethod {
ClassWithAClampMethod clamp(double min, double max) => this;
}
void testNoDoubleClamp(int input) {
final ClassWithAClampMethod nonDoubleClamp = ClassWithAClampMethod();
// ignore: unnecessary_nullable_for_final_variable_declarations
final ClassWithAClampMethod? nonDoubleClamp2 = nonDoubleClamp;
// ignore: unnecessary_nullable_for_final_variable_declarations
final int? nullableInt = input;
final double? nullableDouble = nullableInt?.toDouble();
nonDoubleClamp.clamp(0, 2);
input.clamp(0, 2);
input.clamp(0.0, 2); // bad.
input.toDouble().clamp(0, 2); // bad.
nonDoubleClamp2?.clamp(0, 2);
nullableInt?.clamp(0, 2);
nullableInt?.clamp(0, 2.0); // bad
nullableDouble?.clamp(0, 2); // bad.
// ignore: unused_local_variable
final ClassWithAClampMethod Function(double, double)? tearOff1 = nonDoubleClamp2?.clamp;
// ignore: unused_local_variable
final num Function(num, num)? tearOff2 = nullableInt?.clamp; // bad.
// ignore: unused_local_variable
final num Function(num, num)? tearOff3 = nullableDouble?.clamp; // bad.
}