Do not display generated symbol names in error messages

When an error message reports on a symbol that was generated during
canonicalization, use text like "This value" instead of "This `123`
value". Generated symbols use the identifier index as the symbol name,
since valid Roc variables cannot begin with a number so there's no
chance of collision. We don't want to display generated symbols to the
user, so when building the error message we check if the symbol's name
starts with a digit.
This commit is contained in:
Elias Mulhall 2024-09-03 12:30:37 -04:00
parent 82d0566041
commit f356f6f7a0
No known key found for this signature in database
GPG key ID: 8D1F3C219EAB45F2
3 changed files with 26 additions and 3 deletions

View file

@ -14521,7 +14521,7 @@ All branches in an `if` must have the same type!
4 1 + dbg + 2
^^^
This `63` value is a:
This value is a:
{}
@ -14555,7 +14555,7 @@ All branches in an `if` must have the same type!
4 1 + dbg "" "" + 2
^^^^^^^^^
This `63` value is a:
This value is a:
{}

View file

@ -123,6 +123,21 @@ impl Symbol {
.any(|(_, (s, _))| *s == self)
}
pub fn is_generated(self, interns: &Interns) -> bool {
let ident_ids = interns
.all_ident_ids
.get(&self.module_id())
.unwrap_or_else(|| {
internal_error!(
"ident_string could not find IdentIds for module {:?} in {:?}",
self.module_id(),
interns
)
});
ident_ids.is_generated_id(self.ident_id())
}
pub fn module_string<'a>(&self, interns: &'a Interns) -> &'a ModuleName {
interns
.module_ids
@ -707,6 +722,12 @@ impl IdentIds {
IdentId(self.interner.insert_index_str() as u32)
}
pub fn is_generated_id(&self, id: IdentId) -> bool {
self.interner
.try_get(id.0 as usize)
.map_or(false, |str| str.starts_with(|c: char| c.is_ascii_digit()))
}
#[inline(always)]
pub fn get_id(&self, ident_name: &str) -> Option<IdentId> {
self.interner