Skip to content

Commit

Permalink
Add failing tests (fmt panic) on weird doc comments.
Browse files Browse the repository at this point in the history
  Isolated doc comments causes the compiler to panic with:

  ```
  'no consecutive empty lines'
  ```

  This is reproducible when doc comments are wrapped in sandwich between
  comments and newlines.
  • Loading branch information
KtorZ authored and rvcas committed Mar 16, 2023
1 parent 0feb2df commit 57e217e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/aiken-lang/src/tests/check.rs
Expand Up @@ -322,6 +322,25 @@ fn utf8_hex_literal_warning() {
))
}

#[test]
fn weird_comments() {
let source_code = r#"
// A
/// B
// C
fn foo () {
todo
}
"#;

assert!(matches!(
check(parse(source_code)),
Err((_, Error::UnexpectedDocComment { .. }))
))
}

#[test]
fn discarded_let_bindings() {
let source_code = r#"
Expand Down
26 changes: 26 additions & 0 deletions crates/aiken-lang/src/tests/format.rs
Expand Up @@ -629,3 +629,29 @@ fn test_preserve_pipe() {

assert_fmt(src, expected);
}

#[test]
fn weird_comments() {
let src = indoc! { r#"
// A
/// B
/// C
fn bar () {
todo
}
"#};

let expected = indoc! { r#"
// A
/// B
/// C
fn bar () {
todo
}
"#};

assert_fmt(src, expected);
}
7 changes: 7 additions & 0 deletions crates/aiken-lang/src/tipo/error.rs
Expand Up @@ -892,6 +892,13 @@ The best thing to do from here is to remove it."#))]
#[label("{} arguments", if *count < 2 { "not enough" } else { "too many" })]
location: Span,
},

#[error("I ran into a lonely doc comment not attached to any function definition.")]
#[diagnostic(code("unexpected::doc_comment"))]
UnexpectedDocComment {
#[label("unexpected doc comment")]
location: Span,
},
}

impl Error {
Expand Down

0 comments on commit 57e217e

Please sign in to comment.