From 0b3d5b2e5413f94d8fb5cc62439cbf22ba597723 Mon Sep 17 00:00:00 2001 From: mos Date: Fri, 1 Nov 2024 11:30:13 +0100 Subject: [PATCH] disallow datatype redefining --- bip/src/bp.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bip/src/bp.rs b/bip/src/bp.rs index 09d219e..14005cf 100644 --- a/bip/src/bp.rs +++ b/bip/src/bp.rs @@ -28,6 +28,7 @@ pub enum Error { BadWrite(std::io::Error), NotDefined, ExpectedID, + RedefData, } impl fmt::Display for Error { @@ -37,6 +38,7 @@ impl fmt::Display for Error { Self::BadWrite(e) => write!(f, "{}", e), Self::NotDefined => write!(f, "undefined data type"), Self::ExpectedID => write!(f, "expected identifier"), + Self::RedefData => write!(f, "redefining existing datatype"), } } } @@ -189,7 +191,9 @@ impl Writer { if s == "data" { let lhs = lhs.clone(); let data = self.parse_data_type(rhs); - self.data.insert(lhs, data); + self.data + .insert(lhs, data) + .map_or(Ok(()), |_| Err(Error::RedefData))?; } else { self.parse_id(rhs)?; }