forked from M-Labs/nac3
fixed inference_core and inference_context
This commit is contained in:
parent
67963fc21f
commit
584d8a490f
@ -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;
|
||||
|
@ -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),
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user