From 9afb66116897b637ce5548fbb1fe2bec62b9c0f3 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Fri, 13 Oct 2023 20:53:50 -0400 Subject: [PATCH] fix(typescript): allow generic params and arrow params with same name --- docs/CHANGELOG.md | 3 +++ src/quick-lint-js/fe/variable-analyzer.cpp | 2 +- test/test-variable-analyzer-multiple-declarations.cpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bd00884b4e..a524b1a0f5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -46,6 +46,9 @@ Semantic Versioning. * TypeScript support (still experimental): * A newline after `public`, `protected`, `private`, or `readonly` inside a class is now interpreted correctly. + * `(T: T) => {}` (a generic arrow function with the same name for a + run-time parameter and a generic parameter) no longer falsely reports + [E0034][] ("redeclaration of variable"). * Nested `module` declarations no longer falsely report [E0361][]. E0361's message has been changed: * Before: "module with string name is only allowed at the top level" diff --git a/src/quick-lint-js/fe/variable-analyzer.cpp b/src/quick-lint-js/fe/variable-analyzer.cpp index c659376e60..7b3cdfcf06 100644 --- a/src/quick-lint-js/fe/variable-analyzer.cpp +++ b/src/quick-lint-js/fe/variable-analyzer.cpp @@ -1049,7 +1049,6 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts( (kind == VK::_function && other_kind == VK::_function) || (kind == VK::_function && other_kind == VK::_var) || (kind == VK::_function && other_kind_is_parameter) || - (kind == VK::_function_parameter && other_kind == VK::_generic_parameter) || (kind == VK::_import && other_kind == VK::_interface) || (kind == VK::_interface && other_kind == VK::_class) || (kind == VK::_interface && other_kind == VK::_import) || @@ -1074,6 +1073,7 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts( (kind == VK::_var && other_kind == VK::_var) || (kind == VK::_var && other_kind_is_parameter) || (kind_is_parameter && other_kind == VK::_function) || + (kind_is_parameter && other_kind == VK::_generic_parameter) || (kind_is_parameter && other_kind_is_parameter) || (!is_type(kind) && other_kind == VK::_interface) || // clang-format on diff --git a/test/test-variable-analyzer-multiple-declarations.cpp b/test/test-variable-analyzer-multiple-declarations.cpp index fcb4f80846..f7eeeafc9e 100644 --- a/test/test-variable-analyzer-multiple-declarations.cpp +++ b/test/test-variable-analyzer-multiple-declarations.cpp @@ -121,6 +121,8 @@ TEST(Test_Variable_Analyzer_Multiple_Declarations, function_parameter_can_have_same_name_as_generic_parameter) { test_parse_and_analyze(u8"(function (T) {});"_sv, no_diags, typescript_analyze_options, default_globals); + test_parse_and_analyze(u8"((T) => {});"_sv, no_diags, + typescript_analyze_options, default_globals); } } }