mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
use Entry in some places
This commit is contained in:
parent
5e76e3a97e
commit
f1541d56bd
1 changed files with 15 additions and 6 deletions
|
@ -13,6 +13,7 @@ use roc_types::types::Type::{self, *};
|
||||||
use roc_types::types::{gather_fields_unsorted_iter, Alias, Category, ErrorType, PatternCategory};
|
use roc_types::types::{gather_fields_unsorted_iter, Alias, Category, ErrorType, PatternCategory};
|
||||||
use roc_unify::unify::unify;
|
use roc_unify::unify::unify;
|
||||||
use roc_unify::unify::Unified::*;
|
use roc_unify::unify::Unified::*;
|
||||||
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
|
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
|
||||||
// https://github.com/elm/compiler
|
// https://github.com/elm/compiler
|
||||||
|
@ -435,9 +436,13 @@ fn solve(
|
||||||
|
|
||||||
let mut new_env = env.clone();
|
let mut new_env = env.clone();
|
||||||
for (symbol, loc_var) in local_def_vars.iter() {
|
for (symbol, loc_var) in local_def_vars.iter() {
|
||||||
// better to ask for forgiveness than for permission
|
match new_env.vars_by_symbol.entry(*symbol) {
|
||||||
if let Some(old) = new_env.vars_by_symbol.insert(*symbol, loc_var.value) {
|
Entry::Occupied(_) => {
|
||||||
new_env.vars_by_symbol.insert(*symbol, old);
|
// keep the existing value
|
||||||
|
}
|
||||||
|
Entry::Vacant(vacant) => {
|
||||||
|
vacant.insert(loc_var.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,9 +585,13 @@ fn solve(
|
||||||
|
|
||||||
let mut new_env = env.clone();
|
let mut new_env = env.clone();
|
||||||
for (symbol, loc_var) in local_def_vars.iter() {
|
for (symbol, loc_var) in local_def_vars.iter() {
|
||||||
// when there are duplicates, keep the one from `env`
|
match new_env.vars_by_symbol.entry(*symbol) {
|
||||||
if !new_env.vars_by_symbol.contains_key(symbol) {
|
Entry::Occupied(_) => {
|
||||||
new_env.vars_by_symbol.insert(*symbol, loc_var.value);
|
// keep the existing value
|
||||||
|
}
|
||||||
|
Entry::Vacant(vacant) => {
|
||||||
|
vacant.insert(loc_var.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue