diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 9f9bc8b316..19056c54f3 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -239,7 +239,15 @@ class _DoubleClampVisitor extends RecursiveAstVisitor { @override CompilationUnit? visitMethodInvocation(MethodInvocation node) { - if (node.methodName.name == 'clamp') { + final NodeList arguments = node.argumentList.arguments; + // This may produce false positives when `node.target` is not a subtype of + // num. The static type of `node.target` isn't guaranteed to be resolved at + // this time. Check whether the argument list consists of 2 positional args + // to reduce false positives. + final bool isNumClampInvocation = node.methodName.name == 'clamp' + && arguments.length == 2 + && !arguments.any((Expression exp) => exp is NamedExpression); + if (isNumClampInvocation) { final _Line line = _getLine(parseResult, node.function.offset); if (!line.content.contains('// ignore_clamp_double_lint')) { clamps.add(line);