Fix bug in constant interpolated string.

This commit is contained in:
Stephen Chung
2022-07-29 10:49:03 +08:00
parent fc976172e7
commit 1073a7bd54
4 changed files with 22 additions and 5 deletions

View File

@@ -5,12 +5,16 @@ use crate::engine::{KEYWORD_FN_PTR, OP_EXCLUSIVE_RANGE, OP_INCLUSIVE_RANGE};
use crate::func::hashing::ALT_ZERO_HASH;
use crate::tokenizer::Token;
use crate::types::dynamic::Union;
use crate::{calc_fn_hash, Dynamic, FnPtr, Identifier, ImmutableString, Position, StaticVec, INT};
use crate::{
calc_fn_hash, Dynamic, FnPtr, Identifier, ImmutableString, Position, SmartString, StaticVec,
INT,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
collections::BTreeMap,
fmt,
fmt::Write,
hash::Hash,
iter::once,
num::{NonZeroU8, NonZeroUsize},
@@ -576,6 +580,16 @@ impl Expr {
}))
}
// Interpolated string
Self::InterpolatedString(x, ..) if self.is_constant() => {
let mut s = SmartString::new_const();
for segment in x.iter() {
let v = segment.get_literal_value().unwrap();
write!(&mut s, "{}", v).unwrap();
}
s.into()
}
// Fn
Self::FnCall(ref x, ..)
if !x.is_qualified() && x.args.len() == 1 && x.name == KEYWORD_FN_PTR =>