Skip to content

Commit

Permalink
fix: bad parsing for module select type annotations closes #550
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed May 30, 2023
1 parent 28a9152 commit 2860bac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/parser.rs
Expand Up @@ -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(),
Expand Down
49 changes: 49 additions & 0 deletions crates/aiken-lang/src/tests/parser.rs
Expand Up @@ -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#"
Expand Down

0 comments on commit 2860bac

Please sign in to comment.