diff options
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"), } } |