diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index 8d2e39f..9006a59 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -1,4 +1,5 @@ use crate::{ + codegen::stmt::gen_block, symbol_resolver::{StaticValue, SymbolResolver}, toplevel::{TopLevelContext, TopLevelDef}, typecheck::{ @@ -160,7 +161,7 @@ pub struct CodeGenContext<'ctx, 'a> { impl<'ctx, 'a> CodeGenContext<'ctx, 'a> { pub fn is_terminated(&self) -> bool { - self.builder.get_insert_block().unwrap().get_terminator().is_some() + self.builder.get_insert_block().and_then(|bb| bb.get_terminator()).is_some() } } @@ -854,10 +855,7 @@ pub fn gen_func<'ctx, G: CodeGenerator>( ) -> Result<(Builder<'ctx>, Module<'ctx>, FunctionValue<'ctx>), (Builder<'ctx>, String)> { let body = task.body.clone(); gen_func_impl(context, generator, registry, builder, module, task, |generator, ctx| { - for stmt in body.iter() { - generator.gen_stmt(ctx, stmt)?; - } - Ok(()) + gen_block(generator, ctx, body.iter()) }) } diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index c2dc884..2c4b28b 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -295,7 +295,7 @@ impl<'a> Inferencer<'a> { let mut ret = false; for stmt in block { if ret { - return Err(format!("dead code at {:?}", stmt.location)); + println!("warning: dead code at {:?}\n", stmt.location) } if self.check_stmt(stmt, defined_identifiers)? { ret = true; diff --git a/nac3standalone/demo/src/dead_code_issue118.py b/nac3standalone/demo/src/dead_code_issue118.py new file mode 100644 index 0000000..c1f6222 --- /dev/null +++ b/nac3standalone/demo/src/dead_code_issue118.py @@ -0,0 +1,8 @@ +def f(): + return + return + +def run() -> int32: + f() + + return 0 \ No newline at end of file