diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-04 23:50:46 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-04 23:50:46 +0300 |
commit | fdae943090463526423f5e43e72cd2f0e8147a1b (patch) | |
tree | 5a7212555d8511df16fe6bbcc54b863ec9463b46 /src/type/display.rs | |
parent | 36d2818d39e61b752923e253f8455f50510cb428 (diff) | |
download | myslip-fdae943090463526423f5e43e72cd2f0e8147a1b.tar.gz myslip-fdae943090463526423f5e43e72cd2f0e8147a1b.zip |
Added repl and some documentation. Improved error messages. Removed dead code.
* Removed same_variant in parse::parsetree
* Added SExp::multistep (for use of the repl)
Improved error messages:
* Added parenthesis around types
* Changed how errors propagate inferring generics:
added the error variant ArgumentsDontMatchGeneric,
implemented the displaying of it, added tests for
it.
* Had to change some tests to match for the new changes
Diffstat (limited to 'src/type/display.rs')
-rw-r--r-- | src/type/display.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/type/display.rs b/src/type/display.rs index be51858..68d7fec 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -11,13 +11,13 @@ impl fmt::Display for Type { /// ```rust /// use melisp::r#type::{Type::*, util::*}; /// assert_eq!(Integer.to_string(), "Int".to_string()); - /// assert_eq!(arr(Integer, Integer).to_string(), "Int -> Int".to_string()); + /// assert_eq!(arr(Integer, Integer).to_string(), "(Int -> Int)".to_string()); /// assert_eq!(List(vec![Integer, Integer, Integer]).to_string(), "(Int Int Int)".to_string()); /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Integer => write!(f, "{}", "Int"), - Arrow(a, b) => write!(f, "{} -> {}", a, b), + Arrow(a, b) => write!(f, "({} -> {})", a, b), List(types) => write!( f, "({})", @@ -50,7 +50,7 @@ impl fmt::Display for TypeError { /// expected: arr(VarType("?".to_string()), VarType("?".to_string())), /// found: Integer /// }.to_string(), - /// "invalid operator: '1'\nexpected: '? -> ?'\nfound: 'Int'".to_string() + /// "invalid operator: '1'\nexpected: '(? -> ?)'\nfound: 'Int'".to_string() /// ); /// assert_eq!( /// InvalidArgList { @@ -64,6 +64,13 @@ impl fmt::Display for TypeError { /// UnboundGeneric(String::from("?")).to_string(), /// "unbound generic type: '?'".to_string() /// ); + /// assert_eq!( + /// ArgumentsDontMatchGeneric { + /// argtype: Integer, + /// generictype: arr(VarType("T".to_string()), Integer) + /// }.to_string(), + /// "incompatible argument type 'Int' and generic operator type '(T -> Int)'".to_string() + /// ); /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -83,6 +90,13 @@ impl fmt::Display for TypeError { arglist, expected, found ) }, + ArgumentsDontMatchGeneric { argtype, generictype } => { + write!( + f, + "incompatible argument type '{}' and generic operator type '{}'", + argtype, generictype + ) + }, OtherError => write!(f, "uncategorized error"), } } |