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();
|
let (_, level) = self.stack.sym_def.last().unwrap();
|
||||||
if *level > self.stack.level {
|
if *level > self.stack.level {
|
||||||
let (name, _) = self.stack.sym_def.pop().unwrap();
|
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);
|
poped_names.push(name);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,7 +47,7 @@ fn find_subst(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| !v_b.bound.contains(x))
|
.filter(|x| !v_b.bound.contains(x))
|
||||||
.collect();
|
.collect();
|
||||||
if diff.is_empty() {
|
if !diff.is_empty() {
|
||||||
return Err("different domain".to_string());
|
return Err("different domain".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,10 +200,10 @@ pub fn resolve_call(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::rc::Rc;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::context::TopLevelContext;
|
use crate::context::TopLevelContext;
|
||||||
use crate::primitives::*;
|
use crate::primitives::*;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
fn get_inference_context(ctx: TopLevelContext) -> InferenceContext {
|
fn get_inference_context(ctx: TopLevelContext) -> InferenceContext {
|
||||||
InferenceContext::new(ctx, Box::new(|_| Err("unbounded identifier".into())))
|
InferenceContext::new(ctx, Box::new(|_| Err("unbounded identifier".into())))
|
||||||
|
@ -214,10 +214,7 @@ mod tests {
|
||||||
let mut ctx = basic_ctx();
|
let mut ctx = basic_ctx();
|
||||||
let v1 = ctx.add_variable(VarDef {
|
let v1 = ctx.add_variable(VarDef {
|
||||||
name: "V1",
|
name: "V1",
|
||||||
bound: vec![
|
bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)],
|
||||||
ctx.get_primitive(INT32_TYPE),
|
|
||||||
ctx.get_primitive(FLOAT_TYPE),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
let v1 = ctx.get_variable(v1);
|
let v1 = ctx.get_variable(v1);
|
||||||
let v2 = ctx.add_variable(VarDef {
|
let v2 = ctx.add_variable(VarDef {
|
||||||
|
@ -256,13 +253,11 @@ mod tests {
|
||||||
Err("incorrect parameter number".to_string())
|
Err("incorrect parameter number".to_string())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_call(&ctx, None, "float", &[v1]),
|
resolve_call(&ctx, None, "float", &[v1]),
|
||||||
Ok(Some(ctx.get_primitive(FLOAT_TYPE)))
|
Ok(Some(ctx.get_primitive(FLOAT_TYPE)))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_call(&ctx, None, "float", &[v2]),
|
resolve_call(&ctx, None, "float", &[v2]),
|
||||||
Err("different domain".to_string())
|
Err("different domain".to_string())
|
||||||
|
@ -280,18 +275,12 @@ mod tests {
|
||||||
let v0 = ctx.get_variable(v0);
|
let v0 = ctx.get_variable(v0);
|
||||||
let v1 = ctx.add_variable(VarDef {
|
let v1 = ctx.add_variable(VarDef {
|
||||||
name: "V1",
|
name: "V1",
|
||||||
bound: vec![
|
bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)],
|
||||||
ctx.get_primitive(INT32_TYPE),
|
|
||||||
ctx.get_primitive(FLOAT_TYPE),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
let v1 = ctx.get_variable(v1);
|
let v1 = ctx.get_variable(v1);
|
||||||
let v2 = ctx.add_variable(VarDef {
|
let v2 = ctx.add_variable(VarDef {
|
||||||
name: "V2",
|
name: "V2",
|
||||||
bound: vec![
|
bound: vec![ctx.get_primitive(INT32_TYPE), ctx.get_primitive(FLOAT_TYPE)],
|
||||||
ctx.get_primitive(INT32_TYPE),
|
|
||||||
ctx.get_primitive(FLOAT_TYPE),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
let v2 = ctx.get_variable(v2);
|
let v2 = ctx.get_variable(v2);
|
||||||
let v3 = ctx.add_variable(VarDef {
|
let v3 = ctx.add_variable(VarDef {
|
||||||
|
@ -390,9 +379,7 @@ mod tests {
|
||||||
ctx.add_fn(
|
ctx.add_fn(
|
||||||
"foo1",
|
"foo1",
|
||||||
FnDef {
|
FnDef {
|
||||||
args: vec![
|
args: vec![ParametricType(TUPLE_TYPE, vec![v0.clone(), v0.clone(), v1]).into()],
|
||||||
ParametricType(TUPLE_TYPE, vec![v0.clone(), v0.clone(), v1]).into(),
|
|
||||||
],
|
|
||||||
result: Some(v0),
|
result: Some(v0),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue