diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-12 12:12:39 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-12 12:12:39 +0300 |
commit | db736d795b759edd913d96195747f0881c4e950f (patch) | |
tree | 14cdf8e53810162857ff3a6ee672b9fd8e6ccbff /src/type/display.rs | |
parent | 2e17ad5361a86d004ca48419a0f69f9c298ec1e1 (diff) | |
download | myslip-db736d795b759edd913d96195747f0881c4e950f.tar.gz myslip-db736d795b759edd913d96195747f0881c4e950f.zip |
test: added failing tests for pattern match typing and matches_type
Diffstat (limited to 'src/type/display.rs')
-rw-r--r-- | src/type/display.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/type/display.rs b/src/type/display.rs index 758fee4..e945eba 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -1,6 +1,15 @@ use std::fmt; -use crate::r#type::{Type, TypeError, FunDefError, Type::*, TypeError::*, FunDefError::*}; +use crate::r#type::{ + Type, + TypeError, + FunDefError, + PatFail, + Type::*, + TypeError::*, + FunDefError::*, + PatFail::* +}; impl fmt::Display for Type { @@ -98,6 +107,7 @@ impl fmt::Display for TypeError { arglist, expected, found ) }, + InvalidPattern(ty) => write!(f, "invalid pattern: {ty}"), ArgumentsDontMatchGeneric { argtype, generictype } => { write!( f, @@ -120,6 +130,23 @@ impl fmt::Display for TypeError { } +impl fmt::Display for PatFail { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RepeatedVariable(name, exp_in) => + write!(f, "repeated pattern variable '{name}' in '{exp_in}'"), + TypeMismatch { pattern, expected, found } => + write!( + f, + "type mismatch in '{}' — expected type '{}', found '{}'", + pattern, + expected, + found, + ), + } + } +} + impl fmt::Display for FunDefError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { |