Skip to content

Commit bfa2317

Browse files
committed
better function names and improve documentation
1 parent fb39c88 commit bfa2317

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

compiler-core/src/type_/environment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,14 @@ impl Environment<'_> {
609609
// Check this in the hydrator, i.e. is it a created type
610610
let v = self.new_unbound_var();
611611
let _ = ids.insert(*id, v.clone());
612-
let new_id = self.previous_uid();
613-
self.names.map_new_variable(*id, new_id);
612+
613+
// Preserve any user-provided name from the original generic variable
614+
// for the new unbound variable. This ensures error messages and type
615+
// displays continue to use meaningful names (e.g., "something") rather
616+
// than auto-generated ones (e.g., "a", "b").
617+
let v_id = self.previous_uid();
618+
self.names.reassign_type_variable_alias(*id, v_id);
619+
614620
return v;
615621
}
616622
}

compiler-core/src/type_/printer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ impl Names {
208208
_ = self.type_variables.insert(id, local_alias.clone());
209209
}
210210

211-
pub fn map_new_variable(&mut self, old_id: u64, new_id: u64) {
212-
if let Some(alias) = self.type_variables.get(&old_id) {
213-
_ = self.type_variables.insert(new_id, alias.clone());
211+
/// Assigns `source_id` alias to `target_id`. This is useful when type variables are unified
212+
/// and we need to preserve the original name for consistent error messages and type display.
213+
pub fn reassign_type_variable_alias(&mut self, source_id: u64, target_id: u64) {
214+
if let Some(alias) = self.type_variables.get(&source_id) {
215+
_ = self.type_variables.insert(target_id, alias.clone());
214216
}
215217
}
216218

0 commit comments

Comments
 (0)