Skip to content

Commit c957690

Browse files
committed
better function names and improve documentation
1 parent 1cacebe commit c957690

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

compiler-core/src/type_/environment.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,14 @@ impl Environment<'_> {
596596
// Check this in the hydrator, i.e. is it a created type
597597
let v = self.new_unbound_var();
598598
let _ = ids.insert(*id, v.clone());
599-
let new_id = self.previous_uid();
600-
self.names.map_new_variable(*id, new_id);
599+
600+
// Preserve any user-provided name from the original generic variable
601+
// for the new unbound variable. This ensures error messages and type
602+
// displays continue to use meaningful names (e.g., "something") rather
603+
// than auto-generated ones (e.g., "a", "b").
604+
let v_id = self.previous_uid();
605+
self.names.reassign_type_variable_alias(*id, v_id);
606+
601607
return v;
602608
}
603609
}

compiler-core/src/type_/printer.rs

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

184-
pub fn map_new_variable(&mut self, old_id: u64, new_id: u64) {
185-
if let Some(alias) = self.type_variables.get(&old_id) {
186-
_ = self.type_variables.insert(new_id, alias.clone());
184+
/// Assigns `source_id` alias to `target_id`. This is useful when type variables are unified
185+
/// and we need to preserve the original name for consistent error messages and type display.
186+
pub fn reassign_type_variable_alias(&mut self, source_id: u64, target_id: u64) {
187+
if let Some(alias) = self.type_variables.get(&source_id) {
188+
_ = self.type_variables.insert(target_id, alias.clone());
187189
}
188190
}
189191

0 commit comments

Comments
 (0)