From 584d8a490f53da539cde7f06c4e31f3fd0c9f676 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Mon, 4 Jan 2021 13:24:29 +0800 Subject: [PATCH] fixed inference_core and inference_context --- nac3core/src/context/inference_context.rs | 2 +- nac3core/src/inference_core.rs | 25 ++++++----------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/nac3core/src/context/inference_context.rs b/nac3core/src/context/inference_context.rs index fd056eb06..a03889f75 100644 --- a/nac3core/src/context/inference_context.rs +++ b/nac3core/src/context/inference_context.rs @@ -84,7 +84,7 @@ impl<'a> InferenceContext<'a> { let (_, level) = self.stack.sym_def.last().unwrap(); if *level > self.stack.level { let (name, _) = self.stack.sym_def.pop().unwrap(); - self.sym_table.get_mut(name).unwrap().1 = false; + self.sym_table.remove(name).unwrap(); poped_names.push(name); } else { break; diff --git a/nac3core/src/inference_core.rs b/nac3core/src/inference_core.rs index 1b8d8cb2d..8e7796a35 100644 --- a/nac3core/src/inference_core.rs +++ b/nac3core/src/inference_core.rs @@ -47,7 +47,7 @@ fn find_subst( .iter() .filter(|x| !v_b.bound.contains(x)) .collect(); - if diff.is_empty() { + if !diff.is_empty() { return Err("different domain".to_string()); } } @@ -200,10 +200,10 @@ pub fn resolve_call( #[cfg(test)] mod tests { - use std::rc::Rc; use super::*; use crate::context::TopLevelContext; use crate::primitives::*; + use std::rc::Rc; fn get_inference_context(ctx: TopLevelContext) -> InferenceContext { InferenceContext::new(ctx, Box::new(|_| Err("unbounded identifier".into()))) @@ -214,10 +214,7 @@ mod tests { let mut ctx = basic_ctx(); let v1 = ctx.add_variable(VarDef { name: "V1", - bound: vec![ - ctx.get_primitive(INT32_TYPE), - ctx.get_primitive(FLOAT_TYPE), - ], + bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)], }); let v1 = ctx.get_variable(v1); let v2 = ctx.add_variable(VarDef { @@ -256,13 +253,11 @@ mod tests { Err("incorrect parameter number".to_string()) ); - assert_eq!( resolve_call(&ctx, None, "float", &[v1]), Ok(Some(ctx.get_primitive(FLOAT_TYPE))) ); - assert_eq!( resolve_call(&ctx, None, "float", &[v2]), Err("different domain".to_string()) @@ -280,18 +275,12 @@ mod tests { let v0 = ctx.get_variable(v0); let v1 = ctx.add_variable(VarDef { name: "V1", - bound: vec![ - ctx.get_primitive(INT32_TYPE), - ctx.get_primitive(FLOAT_TYPE), - ], + bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)], }); let v1 = ctx.get_variable(v1); let v2 = ctx.add_variable(VarDef { name: "V2", - bound: vec![ - ctx.get_primitive(INT32_TYPE), - ctx.get_primitive(FLOAT_TYPE), - ], + bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)], }); let v2 = ctx.get_variable(v2); let v3 = ctx.add_variable(VarDef { @@ -390,9 +379,7 @@ mod tests { ctx.add_fn( "foo1", FnDef { - args: vec![ - ParametricType(TUPLE_TYPE, vec![v0.clone(), v0.clone(), v1]).into(), - ], + args: vec![ParametricType(TUPLE_TYPE, vec![v0.clone(), v0.clone(), v1]).into()], result: Some(v0), }, );