From db736d795b759edd913d96195747f0881c4e950f Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Tue, 12 Aug 2025 12:12:39 +0300 Subject: test: added failing tests for pattern match typing and matches_type --- src/type/display.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/type/display.rs') 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 { -- cgit v1.2.3