From f5b8b588267696cec1b399065a0440f314515886 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 21 Aug 2021 15:11:01 +0800 Subject: [PATCH] added tuple assignment check --- nac3core/src/typecheck/function_check.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index 92509ccc..23cd80e2 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -1,3 +1,5 @@ +use crate::typecheck::typedef::TypeEnum; + use super::type_inferencer::Inferencer; use super::typedef::Type; use rustpython_parser::ast::{self, Expr, ExprKind, Stmt, StmtKind}; @@ -22,6 +24,17 @@ impl<'a> Inferencer<'a> { } 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), } }