added tuple assignment check
This commit is contained in:
parent
c4d6b3691a
commit
f5b8b58826
@ -1,3 +1,5 @@
|
|||||||
|
use crate::typecheck::typedef::TypeEnum;
|
||||||
|
|
||||||
use super::type_inferencer::Inferencer;
|
use super::type_inferencer::Inferencer;
|
||||||
use super::typedef::Type;
|
use super::typedef::Type;
|
||||||
use rustpython_parser::ast::{self, Expr, ExprKind, Stmt, StmtKind};
|
use rustpython_parser::ast::{self, Expr, ExprKind, Stmt, StmtKind};
|
||||||
@ -22,6 +24,17 @@ impl<'a> Inferencer<'a> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
ExprKind::Subscript { value, slice, .. } => {
|
||||||
|
self.check_expr(value, defined_identifiers)?;
|
||||||
|
self.check_expr(slice, defined_identifiers)?;
|
||||||
|
if let TypeEnum::TTuple { .. } = &*self.unifier.get_ty(value.custom.unwrap()) {
|
||||||
|
return Err(format!(
|
||||||
|
"Error at {}: cannot assign to tuple element",
|
||||||
|
value.location
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
_ => self.check_expr(pattern, defined_identifiers),
|
_ => self.check_expr(pattern, defined_identifiers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user