Improve repr for type(none) and type(auto) (#4730)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Lingkang 2024-08-16 03:53:59 +08:00 committed by GitHub
parent ccd4524106
commit 0edd8ec93d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -5,7 +5,9 @@ use ecow::{eco_format, EcoString};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use crate::diag::StrResult; use crate::diag::StrResult;
use crate::foundations::{cast, func, Func, NativeFuncData, Repr, Scope, Value}; use crate::foundations::{
cast, func, AutoValue, Func, NativeFuncData, NoneValue, Repr, Scope, Value,
};
use crate::utils::Static; use crate::utils::Static;
#[rustfmt::skip] #[rustfmt::skip]
@ -148,7 +150,14 @@ impl Debug for Type {
impl Repr for Type { impl Repr for Type {
fn repr(&self) -> EcoString { fn repr(&self) -> EcoString {
self.long_name().into() if *self == Type::of::<AutoValue>() {
"type(auto)"
} else if *self == Type::of::<NoneValue>() {
"type(none)"
} else {
self.long_name()
}
.into()
} }
} }

View File

@ -727,6 +727,9 @@ mod tests {
fn test_value_debug() { fn test_value_debug() {
// Primitives. // Primitives.
test(Value::None, "none"); test(Value::None, "none");
test(Value::Auto, "auto");
test(Value::None.ty(), "type(none)");
test(Value::Auto.ty(), "type(auto)");
test(false, "false"); test(false, "false");
test(12i64, "12"); test(12i64, "12");
test(3.24, "3.24"); test(3.24, "3.24");

View File

@ -23,3 +23,9 @@
--- issue-3110-associated-function --- --- issue-3110-associated-function ---
// Error: 6-18 type string does not contain field `from-unïcode` // Error: 6-18 type string does not contain field `from-unïcode`
#str.from-unïcode(97) #str.from-unïcode(97)
--- issue-2747-repr-auto-none ---
#test(repr(none), "none")
#test(repr(auto), "auto")
#test(repr(type(none)), "type(none)")
#test(repr(type(auto)), "type(auto)")