Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error gracefully when @main is missing #346

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading