diff options
author | Nadrieril | 2019-08-21 17:40:56 +0200 |
---|---|---|
committer | Nadrieril | 2019-08-21 17:40:56 +0200 |
commit | e8a9178ebe4860a8a00a6ec8f77b661fdad84890 (patch) | |
tree | cdf74ed87a9c4cfb3adf64e0e0a95e99bb54efed /dhall/src | |
parent | 6c006e122a050ebbe76c8c566e559bbf9f2301a7 (diff) |
Don't use take_mut::take lightly since normalize_whnf might panic
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/core/value.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index e1623a8..69d372a 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -61,16 +61,25 @@ impl ValueInternal { } fn normalize_whnf(&mut self) { - take_mut::take(self, |vint| match &vint.form { - Unevaled => ValueInternal { - form: WHNF, - // TODO: thunk chaining - value: normalize_whnf(vint.value).into_whnf(), - ty: vint.ty, + take_mut::take_or_recover( + self, + // Dummy value in case the other closure panics + || ValueInternal { + form: Unevaled, + value: ValueF::Const(Const::Type), + ty: None, }, - // Already in WHNF - WHNF | NF => vint, - }) + |vint| match &vint.form { + Unevaled => ValueInternal { + form: WHNF, + // TODO: thunk chaining + value: normalize_whnf(vint.value).into_whnf(), + ty: vint.ty, + }, + // Already in WHNF + WHNF | NF => vint, + }, + ) } fn normalize_nf(&mut self) { match self.form { |