aboutsummaryrefslogtreecommitdiff
path: root/src/type/display.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-03 16:06:43 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-03 16:06:43 +0300
commitac9ecc754e12487eb20a615ca3cf05cb163ea75a (patch)
tree1dcd5f9984d04404c399d1cd2134a1148d3d2b32 /src/type/display.rs
parent00cf7eb0a1316ce0e330ed9a1e218fc60ae0b8cd (diff)
downloadmyslip-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/display.rs')
-rw-r--r--src/type/display.rs9
1 files changed, 7 insertions, 2 deletions
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::<Vec<String>>()
.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,