Fix multi-line type-alias tuple definitions

Somehow missed it when reworking tuples. We need to allow the new
  'NewLineLeftParen' token in this situation as well. Especially because
  this is what the formatter outputs.
This commit is contained in:
KtorZ 2023-01-16 11:30:20 +01:00
parent 1adac64585
commit 844570caf5
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 41 additions and 1 deletions

View File

@ -1388,7 +1388,10 @@ pub fn type_parser() -> impl Parser<Token, ast::Annotation, Error = ParseError>
.separated_by(just(Token::Comma))
.at_least(2)
.allow_trailing()
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(
choice((just(Token::LeftParen), just(Token::NewLineLeftParen))),
just(Token::RightParen),
)
.map_with_span(|elems, span| ast::Annotation::Tuple {
location: span,
elems,

View File

@ -1911,3 +1911,40 @@ fn function_ambiguous_sequence() {
],
)
}
#[test]
fn tuple_type_alias() {
let code = indoc! {r#"
type RoyaltyToken =
(PolicyId, AssetName)
"#};
assert_definitions(
code,
vec![ast::UntypedDefinition::TypeAlias(TypeAlias {
alias: "RoyaltyToken".to_string(),
annotation: ast::Annotation::Tuple {
location: Span::new((), 22..43),
elems: vec![
ast::Annotation::Constructor {
location: Span::new((), 23..31),
module: None,
name: "PolicyId".to_string(),
arguments: vec![],
},
ast::Annotation::Constructor {
location: Span::new((), 33..42),
module: None,
name: "AssetName".to_string(),
arguments: vec![],
},
],
},
doc: None,
location: Span::new((), 0..43),
parameters: vec![],
public: false,
tipo: (),
})],
)
}