fix: bad parsing for module select type annotations closes #550

This commit is contained in:
rvcas 2023-05-30 10:39:28 -04:00
parent 28a9152f09
commit 2860bac4c6
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 50 additions and 1 deletions

View File

@ -1519,7 +1519,7 @@ pub fn type_parser() -> impl Parser<Token, ast::Annotation, Error = ParseError>
.then(
r.separated_by(just(Token::Comma))
.allow_trailing()
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(just(Token::Less), just(Token::Greater))
.or_not(),
)
.or_not(),

View File

@ -38,6 +38,55 @@ fn windows_newline() {
)
}
#[test]
fn type_annotation_with_module_prefix() {
let code = indoc! {r#"
use aiken
pub fn go() -> aiken.Option<Int> {
False
}
"#};
assert_definitions(
code,
vec![
ast::UntypedDefinition::Use(ast::Use {
as_name: None,
location: Span::new((), 0..9),
module: vec!["aiken".to_string()],
package: (),
unqualified: vec![],
}),
ast::UntypedDefinition::Fn(ast::Function {
arguments: vec![],
body: expr::UntypedExpr::Var {
location: Span::new((), 48..53),
name: "False".to_string(),
},
doc: None,
location: Span::new((), 11..43),
name: "go".to_string(),
public: true,
return_annotation: Some(ast::Annotation::Constructor {
location: Span::new((), 26..43),
module: Some("aiken".to_string()),
name: "Option".to_string(),
arguments: vec![ast::Annotation::Constructor {
location: Span::new((), 39..42),
module: None,
name: "Int".to_string(),
arguments: vec![],
}],
}),
return_type: (),
end_position: 54,
can_error: true,
}),
],
)
}
#[test]
fn test_fail() {
let code = indoc! {r#"