mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
fix: type formatting
This commit is contained in:
parent
5b8715af27
commit
448fe4e64c
2 changed files with 37 additions and 2 deletions
|
@ -170,6 +170,42 @@ impl Constraint {
|
|||
Self::Sandwiched { sub, sup }
|
||||
}
|
||||
|
||||
pub fn named_fmt(&self, f: &mut fmt::Formatter<'_>, name: &str, limit: usize) -> fmt::Result {
|
||||
if limit == 0 {
|
||||
return write!(f, "...");
|
||||
}
|
||||
match self {
|
||||
Self::Sandwiched { sub, sup } => match (sub == &Type::Never, sup == &Type::Obj) {
|
||||
(true, true) => {
|
||||
write!(f, "{name}: Type")?;
|
||||
Ok(())
|
||||
}
|
||||
(true, false) => {
|
||||
write!(f, "{name} <: ")?;
|
||||
sup.limited_fmt(f, limit - 1)?;
|
||||
Ok(())
|
||||
}
|
||||
(false, true) => {
|
||||
write!(f, "{name} :> ")?;
|
||||
sub.limited_fmt(f, limit - 1)?;
|
||||
Ok(())
|
||||
}
|
||||
(false, false) => {
|
||||
write!(f, "{name} :> ")?;
|
||||
sub.limited_fmt(f, limit - 1)?;
|
||||
write!(f, ", {name} <: ")?;
|
||||
sup.limited_fmt(f, limit - 1)?;
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
Self::TypeOf(t) => {
|
||||
write!(f, "{name}: ")?;
|
||||
t.limited_fmt(f, limit - 1)
|
||||
}
|
||||
Self::Uninited => write!(f, "Never"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_type_of(t: Type) -> Self {
|
||||
if t == Type::Type {
|
||||
Self::new_sandwiched(Type::Never, Type::Obj)
|
||||
|
|
|
@ -805,8 +805,7 @@ impl LimitedDisplay for Type {
|
|||
if i != 0 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
write!(f, "{name}")?;
|
||||
constr.limited_fmt(f, limit - 1)?;
|
||||
constr.named_fmt(f, name, limit - 1)?;
|
||||
}
|
||||
write!(f, "|")?;
|
||||
quantified.limited_fmt(f, limit - 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue