forked from M-Labs/nac3
list test
This commit is contained in:
parent
3e03398d9b
commit
b3d849ea7a
|
@ -304,7 +304,9 @@ impl<'a> Inferencer<'a> {
|
||||||
|
|
||||||
Ok(Located {
|
Ok(Located {
|
||||||
location,
|
location,
|
||||||
custom: Some(list),
|
custom: Some(new_context.unifier.add_ty(TypeEnum::TList {
|
||||||
|
ty: elt.custom.unwrap(),
|
||||||
|
})),
|
||||||
node: ExprKind::ListComp {
|
node: ExprKind::ListComp {
|
||||||
elt: Box::new(elt),
|
elt: Box::new(elt),
|
||||||
generators: vec![ast::Comprehension {
|
generators: vec![ast::Comprehension {
|
||||||
|
@ -474,7 +476,7 @@ impl<'a> Inferencer<'a> {
|
||||||
for t in elts.iter() {
|
for t in elts.iter() {
|
||||||
self.unifier.unify(ty, t.custom.unwrap())?;
|
self.unifier.unify(ty, t.custom.unwrap())?;
|
||||||
}
|
}
|
||||||
Ok(ty)
|
Ok(self.unifier.add_ty(TypeEnum::TList { ty }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_tuple(&mut self, elts: &[ast::Expr<Option<Type>>]) -> InferenceResult {
|
fn infer_tuple(&mut self, elts: &[ast::Expr<Option<Type>>]) -> InferenceResult {
|
||||||
|
|
|
@ -159,6 +159,13 @@ impl TestEnvironment {
|
||||||
[("a", "fn[[x=bool], bool]"), ("b", "fn[[x=int32], int32]"), ("c", "bool"),
|
[("a", "fn[[x=bool], bool]"), ("b", "fn[[x=int32], int32]"), ("c", "bool"),
|
||||||
("d", "int32"), ("foo1", "Foo[bool]"), ("foo2", "Foo[int32]")].iter().cloned().collect()
|
("d", "int32"), ("foo1", "Foo[bool]"), ("foo2", "Foo[int32]")].iter().cloned().collect()
|
||||||
; "obj test")]
|
; "obj test")]
|
||||||
|
#[test_case(indoc! {"
|
||||||
|
f = lambda x: True
|
||||||
|
a = [1, 2, 3]
|
||||||
|
b = [f(x) for x in a]
|
||||||
|
"},
|
||||||
|
[("a", "list[int32]"), ("b", "list[bool]"), ("f", "fn[[x=int32], bool]")].iter().cloned().collect()
|
||||||
|
; "listcomp test")]
|
||||||
fn test_basic(source: &str, mapping: HashMap<&str, &str>) {
|
fn test_basic(source: &str, mapping: HashMap<&str, &str>) {
|
||||||
let mut env = TestEnvironment::new();
|
let mut env = TestEnvironment::new();
|
||||||
let id_to_name = std::mem::take(&mut env.id_to_name);
|
let id_to_name = std::mem::take(&mut env.id_to_name);
|
||||||
|
|
Loading…
Reference in New Issue