From be392d4001f360be482dfe6730b2eae756f2b9f1 Mon Sep 17 00:00:00 2001 From: Patrick LaFontaine <32135464+Pat-Lafon@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:47:35 -0400 Subject: [PATCH] Move main typecheck to typechecking rather than runtime --- brilirs/src/check.rs | 7 +++++++ brilirs/src/interp.rs | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/brilirs/src/check.rs b/brilirs/src/check.rs index f14a56e12..09075d705 100644 --- a/brilirs/src/check.rs +++ b/brilirs/src/check.rs @@ -508,6 +508,13 @@ fn type_check_instruction<'a>( } fn type_check_func(bbfunc: &BBFunction, bbprog: &BBProgram) -> Result<(), PositionalInterpError> { + if bbfunc.name == "main" { + if bbfunc.return_type.is_some() { + return Err(InterpError::NonEmptyRetForFunc(bbfunc.name.clone())) + .map_err(|e| e.add_pos(bbfunc.pos.clone())); + } + } + let mut env: FxHashMap<&str, &Type> = FxHashMap::with_capacity_and_hasher(20, fxhash::FxBuildHasher::default()); bbfunc.args.iter().for_each(|a| { diff --git a/brilirs/src/interp.rs b/brilirs/src/interp.rs index 17c5a5596..de8d5fdab 100644 --- a/brilirs/src/interp.rs +++ b/brilirs/src/interp.rs @@ -796,11 +796,6 @@ pub fn execute_main( .map(|i| prog.get(i).unwrap()) .ok_or(InterpError::NoMainFunction)?; - if main_func.return_type.is_some() { - return Err(InterpError::NonEmptyRetForFunc(main_func.name.clone())) - .map_err(|e| e.add_pos(main_func.pos.clone())); - } - let mut env = Environment::new(main_func.num_of_vars); let heap = Heap::default();