summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-04-18 22:08:25 +0200
committerNadrieril2019-04-18 22:08:25 +0200
commit486a26eb7cea0c99818fde2c3fd933f7aca40b52 (patch)
treeb627edc56eb123bfc247c913aac5f881bb4a4833 /dhall_core
parent588127bf4105d8d4629304521abc3d992326a63a (diff)
Use a context for substitution in normalization
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/context.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/dhall_core/src/context.rs b/dhall_core/src/context.rs
index b500226..91eec69 100644
--- a/dhall_core/src/context.rs
+++ b/dhall_core/src/context.rs
@@ -32,7 +32,13 @@ impl<K: Hash + Eq + Clone, T> Context<K, T> {
/// lookup k n (insert j v c) = lookup k n c -- k /= j
/// ```
pub fn lookup<'a>(&'a self, k: &K, n: usize) -> Option<&'a T> {
- self.0.get(k).and_then(|v| v.get(v.len() - 1 - n))
+ self.0.get(k).and_then(|v| {
+ if n < v.len() {
+ v.get(v.len() - 1 - n)
+ } else {
+ None
+ }
+ })
}
pub fn map<U, F: Fn(&T) -> U>(&self, f: F) -> Context<K, U> {