diff --git a/lib/Sema/FlowChecker-expr.cpp b/lib/Sema/FlowChecker-expr.cpp index 11ece91f1d5..6d6d72d8cfe 100644 --- a/lib/Sema/FlowChecker-expr.cpp +++ b/lib/Sema/FlowChecker-expr.cpp @@ -1894,10 +1894,17 @@ class FlowChecker::ExprVisitor { auto [argTypeNarrow, cf] = tryNarrowType(argType, expectedType); if (!cf.canFlow) { - outer_.sm_.error( - arg->getSourceRange(), - "ft: " + calleeName + " parameter '" + param.first.str() + - "' type mismatch"); + if (param.first.isValid()) { + outer_.sm_.error( + arg->getSourceRange(), + "ft: " + calleeName + " parameter '" + param.first.str() + + "' type mismatch"); + } else { + outer_.sm_.error( + arg->getSourceRange(), + "ft: " + calleeName + " parameter #" + llvh::Twine(argIndex + 1) + + " type mismatch"); + } return false; } // If a cast is needed, replace the argument with the cast. diff --git a/test/Sema/flow/regress-function-param-no-name-error.js b/test/Sema/flow/regress-function-param-no-name-error.js new file mode 100644 index 00000000000..9b3a5770b41 --- /dev/null +++ b/test/Sema/flow/regress-function-param-no-name-error.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// RUN: (! %shermes -Werror -ferror-limit=0 -typed -dump-sema %s 2>&1 ) | %FileCheckOrRegen --match-full-lines %s + +function f(cb: number => string) { + cb('a'); +} + +// Auto-generated content below. Please do not modify manually. + +// CHECK:{{.*}}regress-function-param-no-name-error.js:11:6: error: ft: function parameter #1 type mismatch +// CHECK-NEXT: cb('a'); +// CHECK-NEXT: ^~~ +// CHECK-NEXT:Emitted 1 errors. exiting.