diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-03 16:06:43 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-03 16:06:43 +0300 |
commit | ac9ecc754e12487eb20a615ca3cf05cb163ea75a (patch) | |
tree | 1dcd5f9984d04404c399d1cd2134a1148d3d2b32 /src/type/mod.rs | |
parent | 00cf7eb0a1316ce0e330ed9a1e218fc60ae0b8cd (diff) | |
download | myslip-ac9ecc754e12487eb20a615ca3cf05cb163ea75a.tar.gz myslip-ac9ecc754e12487eb20a615ca3cf05cb163ea75a.zip |
Changed UndefinedType to VarType(String) for generics and added tests for inferring them.
Inferring is done by method Type::infer_generics.
Whether it is executed is controlled by method Type::is_concrete.
Also had to change the Display for Type and its tests,
as the enum variants changed.
Diffstat (limited to 'src/type/mod.rs')
-rw-r--r-- | src/type/mod.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/type/mod.rs b/src/type/mod.rs index 5e7076a..6c4be97 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -17,7 +17,10 @@ pub enum Type { List(Vec<Type>), - UndefinedType, // only for errors + /// Type for generics + /// and also error messages + /// with unknown types + VarType(String), } @@ -27,6 +30,8 @@ pub enum TypeError { UndefinedVariable(String), + UnboundGeneric(String), + InvalidOperator { operator: SExp, expected: Type, @@ -41,3 +46,30 @@ pub enum TypeError { OtherError } + + +impl Type { + /// Tests if the type has no variable types. + /// + /// **Examples** + /// ```rust + /// use melisp::r#type::{*, Type::*, TypeError::*, util::*}; + /// + /// assert!(Integer.is_concrete()); + /// assert!(!VarType("a".to_string()).is_concrete()); + /// + /// assert!(arr(Integer, Integer).is_concrete()); + /// assert!(!arr(VarType("b".to_string()), Integer).is_concrete()); + /// + /// assert!( + /// List(vec![Integer, Integer, arr(Integer, Integer)]).is_concrete() + /// ); + /// assert!( + /// !List(vec![Integer, VarType("a".to_string()), Integer]) + /// .is_concrete() + /// ); + /// ``` + pub fn is_concrete(&self) -> bool { + todo!() + } +} |