diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 0ad9cdd1..3688b7b0 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -186,7 +186,7 @@ pub fn gen_while<'ctx, 'a, G: CodeGenerator + ?Sized>( ctx: &mut CodeGenContext<'ctx, 'a>, stmt: &Stmt>, ) { - if let StmtKind::While { test, body, orelse } = &stmt.node { + if let StmtKind::While { test, body, orelse, .. } = &stmt.node { let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap(); let test_bb = ctx.ctx.append_basic_block(current, "test"); let body_bb = ctx.ctx.append_basic_block(current, "body"); @@ -228,7 +228,7 @@ pub fn gen_if<'ctx, 'a, G: CodeGenerator + ?Sized>( ctx: &mut CodeGenContext<'ctx, 'a>, stmt: &Stmt>, ) -> bool { - if let StmtKind::If { test, body, orelse } = &stmt.node { + if let StmtKind::If { test, body, orelse, .. } = &stmt.node { let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap(); let test_bb = ctx.ctx.append_basic_block(current, "test"); let body_bb = ctx.ctx.append_basic_block(current, "body"); @@ -306,11 +306,11 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator + ?Sized>( stmt: &Stmt>, ) -> bool { match &stmt.node { - StmtKind::Pass => {} - StmtKind::Expr { value } => { + StmtKind::Pass { .. } => {} + StmtKind::Expr { value, .. } => { generator.gen_expr(ctx, value); } - StmtKind::Return { value } => { + StmtKind::Return { value, .. } => { let value = value.as_ref().map(|v| generator.gen_expr(ctx, v).unwrap()); let value = value.as_ref().map(|v| v as &dyn BasicValue); ctx.builder.build_return(value); @@ -328,11 +328,11 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator + ?Sized>( generator.gen_assign(ctx, target, value); } } - StmtKind::Continue => { + StmtKind::Continue { .. } => { ctx.builder.build_unconditional_branch(ctx.loop_bb.unwrap().0); return true; } - StmtKind::Break => { + StmtKind::Break { .. }=> { ctx.builder.build_unconditional_branch(ctx.loop_bb.unwrap().1); return true; } diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 604262dd..343a68fe 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1395,8 +1395,8 @@ impl TopLevelComposer { return Err("unsupported statement type in class definition body".into()); } } - ast::StmtKind::Pass => {} - ast::StmtKind::Expr { value: _ } => {} // typically a docstring; ignoring all expressions matches CPython behavior + ast::StmtKind::Pass { .. } => {} + ast::StmtKind::Expr { value: _, .. } => {} // typically a docstring; ignoring all expressions matches CPython behavior _ => return Err("unsupported statement type in class definition body".into()), } } diff --git a/nac3core/src/toplevel/helper.rs b/nac3core/src/toplevel/helper.rs index ec4bd184..df792234 100644 --- a/nac3core/src/toplevel/helper.rs +++ b/nac3core/src/toplevel/helper.rs @@ -337,7 +337,7 @@ impl TopLevelComposer { ast::StmtKind::With { body, .. } => { result.extend(Self::get_all_assigned_field(body.as_slice())?); } - ast::StmtKind::Pass => {} + ast::StmtKind::Pass { .. } => {} ast::StmtKind::Assert { .. } => {} ast::StmtKind::Expr { .. } => {} diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index 5b681297..8b432393 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -196,7 +196,7 @@ impl<'a> Inferencer<'a> { } Ok(false) } - StmtKind::If { test, body, orelse } => { + StmtKind::If { test, body, orelse, .. } => { self.check_expr(test, defined_identifiers)?; self.should_have_value(test)?; let mut body_identifiers = defined_identifiers.clone(); @@ -211,7 +211,7 @@ impl<'a> Inferencer<'a> { } Ok(body_returned && orelse_returned) } - StmtKind::While { test, body, orelse } => { + StmtKind::While { test, body, orelse, .. } => { self.check_expr(test, defined_identifiers)?; self.should_have_value(test)?; let mut defined_identifiers = defined_identifiers.clone(); @@ -230,7 +230,7 @@ impl<'a> Inferencer<'a> { self.check_block(body, &mut new_defined_identifiers)?; Ok(false) } - StmtKind::Expr { value } => { + StmtKind::Expr { value, .. } => { self.check_expr(value, defined_identifiers)?; Ok(false) } @@ -250,7 +250,7 @@ impl<'a> Inferencer<'a> { } Ok(false) } - StmtKind::Return { value } => { + StmtKind::Return { value, .. } => { if let Some(value) = value { self.check_expr(value, defined_identifiers)?; self.should_have_value(value)?; diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 1a8fa638..26f544d8 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -80,7 +80,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> { fn fold_stmt(&mut self, node: ast::Stmt<()>) -> Result, Self::Error> { let stmt = match node.node { // we don't want fold over type annotation - ast::StmtKind::AnnAssign { target, annotation, value, simple } => { + ast::StmtKind::AnnAssign { target, annotation, value, simple, config_comment } => { self.infer_pattern(&target)?; let target = Box::new(self.fold_expr(*target)?); let value = if let Some(v) = value { @@ -105,14 +105,14 @@ impl<'a> fold::Fold<()> for Inferencer<'a> { Located { location: node.location, custom: None, - node: ast::StmtKind::AnnAssign { target, annotation, value, simple }, + node: ast::StmtKind::AnnAssign { target, annotation, value, simple, config_comment }, } } ast::StmtKind::For { ref target, .. } => { self.infer_pattern(target)?; fold::fold_stmt(self, node)? } - ast::StmtKind::Assign { ref targets, .. } => { + ast::StmtKind::Assign { ref targets, ref config_comment, .. } => { if targets.iter().all(|t| matches!(t.node, ast::ExprKind::Name { .. })) { if let ast::StmtKind::Assign { targets, value, .. } = node.node { let value = self.fold_expr(*value)?; @@ -158,6 +158,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> { targets, value: Box::new(value), type_comment: None, + config_comment: config_comment.clone() }, custom: None, }); @@ -198,7 +199,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> { } } ast::StmtKind::AnnAssign { .. } | ast::StmtKind::Expr { .. } => {} - ast::StmtKind::Break | ast::StmtKind::Continue | ast::StmtKind::Pass => {} + ast::StmtKind::Break { .. } | ast::StmtKind::Continue { .. } | ast::StmtKind::Pass { .. } => {} ast::StmtKind::With { items, .. } => { for item in items.iter() { let ty = item.context_expr.custom.unwrap(); @@ -272,7 +273,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> { } } } - ast::StmtKind::Return { value } => match (value, self.function_data.return_type) { + ast::StmtKind::Return { value, .. } => match (value, self.function_data.return_type) { (Some(v), Some(v1)) => { self.unify(v.custom.unwrap(), v1, &v.location)?; }