From ac9ecc754e12487eb20a615ca3cf05cb163ea75a Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 3 Aug 2025 16:06:43 +0300 Subject: 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. --- src/type/display.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/type/display.rs') diff --git a/src/type/display.rs b/src/type/display.rs index 781d614..be51858 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -26,7 +26,7 @@ impl fmt::Display for Type { .collect::>() .join(" ") ), - UndefinedType => write!(f, "?"), + VarType(name) => write!(f, "{}", name), } } } @@ -47,7 +47,7 @@ impl fmt::Display for TypeError { /// assert_eq!( /// InvalidOperator { /// operator: Atom(Int(1)), - /// expected: arr(UndefinedType, UndefinedType), + /// expected: arr(VarType("?".to_string()), VarType("?".to_string())), /// found: Integer /// }.to_string(), /// "invalid operator: '1'\nexpected: '? -> ?'\nfound: 'Int'".to_string() @@ -60,10 +60,15 @@ impl fmt::Display for TypeError { /// }.to_string(), /// "invalid argument list: '(1 2 3)'\nexpected: '(Int Int)'\nfound: '(Int Int Int)'".to_string() /// ); + /// assert_eq!( + /// UnboundGeneric(String::from("?")).to_string(), + /// "unbound generic type: '?'".to_string() + /// ); /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { UndefinedVariable(name) => write!(f, "undefined variable: '{}'", name), + UnboundGeneric(name) => write!(f, "unbound generic type: '{}'", name), InvalidOperator { operator, expected, found } => { write!( f, -- cgit v1.2.3