Skip to content

Commit

Permalink
fix(typescript): allow generic params and arrow params with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Oct 14, 2023
1 parent 9576b8d commit 9afb661
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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"
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/variable-analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/test-variable-analyzer-multiple-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(T) {});"_sv, no_diags,
typescript_analyze_options, default_globals);
test_parse_and_analyze(u8"(<T>(T) => {});"_sv, no_diags,
typescript_analyze_options, default_globals);
}
}
}
Expand Down

0 comments on commit 9afb661

Please sign in to comment.