Skip to content

Commit

Permalink
Fix generic pack crash (#404)
Browse files Browse the repository at this point in the history
* Handle generic and variadic packs

* Update tests

* Update changelog

* Redo tests
  • Loading branch information
JohnnyMorganz authored Mar 8, 2022
1 parent 34b104e commit 423c7de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fixed crashed due to unhandled generic type packs under the `luau` feature flag. ([#403](https://github.com/JohnnyMorganz/StyLua/issues/403))

## [0.12.4] - 2022-03-02
### Fixed
Expand Down
3 changes: 2 additions & 1 deletion src/formatters/trivia_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub fn type_info_trailing_trivia(type_info: &TypeInfo) -> Vec<Token> {
let (_, end_brace) = arrows.tokens();
end_brace.trailing_trivia().map(|x| x.to_owned()).collect()
}
TypeInfo::GenericPack { ellipse, .. } => ellipse.trailing_trivia().cloned().collect(),

TypeInfo::Intersection { right, .. } => type_info_trailing_trivia(right),

Expand Down Expand Up @@ -219,7 +220,7 @@ pub fn type_info_trailing_trivia(type_info: &TypeInfo) -> Vec<Token> {

TypeInfo::Union { right, .. } => type_info_trailing_trivia(right),
TypeInfo::Variadic { type_info, .. } => type_info_trailing_trivia(type_info),

TypeInfo::VariadicPack { name, .. } => name.trailing_trivia().cloned().collect(),
other => panic!("unknown node {:?}", other),
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/inputs-luau/types-generic-pack.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type X = {
useMemo: <T...>(nextCreate: () -> T..., deps: Array<any> | nil) -> T...,
}
10 changes: 10 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: tests/tests.rs
assertion_line: 30
expression: format(&contents)

---
type X = {
useMemo: <T...>(nextCreate: () -> T..., deps: Array<any> | nil) -> T...,
}

0 comments on commit 423c7de

Please sign in to comment.