Let type constructor/field access error report the name correctly (#3140)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
712eaaa5f4
commit
23875a0483
@ -94,10 +94,10 @@ impl Type {
|
||||
.constructor
|
||||
.as_ref()
|
||||
.map(|lazy| Func::from(*lazy))
|
||||
.ok_or_else(|| eco_format!("type self does not have a constructor"))
|
||||
.ok_or_else(|| eco_format!("type {self} does not have a constructor"))
|
||||
}
|
||||
|
||||
/// The type's associated scope of sub-definition.
|
||||
/// The type's associated scope that holds sub-definitions.
|
||||
pub fn scope(&self) -> &'static Scope {
|
||||
&(self.0).0.scope
|
||||
}
|
||||
@ -106,13 +106,13 @@ impl Type {
|
||||
pub fn field(&self, field: &str) -> StrResult<&'static Value> {
|
||||
self.scope()
|
||||
.get(field)
|
||||
.ok_or_else(|| eco_format!("type self does not contain field `{}`", field))
|
||||
.ok_or_else(|| eco_format!("type {self} does not contain field `{field}`"))
|
||||
}
|
||||
}
|
||||
|
||||
// Type compatibility.
|
||||
impl Type {
|
||||
/// The type's backwards-compatible name.
|
||||
/// The type's backward-compatible name.
|
||||
pub fn compat_name(&self) -> &str {
|
||||
self.long_name()
|
||||
}
|
||||
|
15
tests/typ/bugs/3110-no-type-ctor-or-field.typ
Normal file
15
tests/typ/bugs/3110-no-type-ctor-or-field.typ
Normal file
@ -0,0 +1,15 @@
|
||||
// Issue #3110: let the error message report the type name.
|
||||
// https://github.com/typst/typst/issues/3110
|
||||
// Ref: false
|
||||
|
||||
---
|
||||
// Error: 2-9 type content does not have a constructor
|
||||
#content()
|
||||
|
||||
---
|
||||
// Error: 6-12 type integer does not contain field `MAXVAL`
|
||||
#int.MAXVAL
|
||||
|
||||
---
|
||||
// Error: 6-18 type string does not contain field `from-unïcode`
|
||||
#str.from-unïcode(97)
|
Loading…
x
Reference in New Issue
Block a user