Skip to content

Commit

Permalink
error gracefully when @main is missing (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricozb authored May 28, 2024
2 parents 3c3af24 + 9aca366 commit 093af58
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,17 @@ impl Book {
}
let mut book = hvm::Book { defs: Vec::new() };
for (fid, name) in &fid_to_name {
if let Some(ast_def) = self.defs.get(name) {
let mut def = hvm::Def {
name: name.clone(),
safe: true,
root: hvm::Port(0),
rbag: vec![],
node: vec![],
vars: 0,
};
ast_def.build(&mut def, &name_to_fid, &mut BTreeMap::new());
book.defs.push(def);
}
let ast_def = self.defs.get(name).expect("missing `@main` definition");
let mut def = hvm::Def {
name: name.clone(),
safe: true,
root: hvm::Port(0),
rbag: vec![],
node: vec![],
vars: 0,
};
ast_def.build(&mut def, &name_to_fid, &mut BTreeMap::new());
book.defs.push(def);
}
return book;
}
Expand Down
Empty file added tests/programs/empty.hvm
Empty file.
2 changes: 1 addition & 1 deletion tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn execute_hvm(args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
stderr.read_to_string(&mut output)?;

Ok(if !status.success() {
format!("exited with code {status}:\n{output}")
format!("{status}\n{output}")
} else {
parse_output(&output).unwrap_or_else(|err| {
panic!("error parsing output:\n{err}\n\n{output}")
Expand Down
9 changes: 9 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: tests/run.rs
expression: rust_output
input_file: tests/programs/empty.hvm
---
exit status: 101
thread 'main' panicked at src/ast.rs:508:41:
missing `@main` definition
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 comments on commit 093af58

Please sign in to comment.