difftreelog
test pointer-size invariant snapshots
in: master
10 files changed
crates/jrsonnet-evaluator/src/analyze.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/analyze.rs
+++ b/crates/jrsonnet-evaluator/src/analyze.rs
@@ -1959,48 +1959,6 @@
}
}
-#[cfg(test)]
-fn render_diagnostics(src: &str, diags: &[Diagnostic]) -> String {
- use std::fmt::Write;
-
- use hi_doc::{Formatting, SnippetBuilder, Text};
-
- let mut out = String::new();
- let mut unspanned = Vec::new();
- let mut spanned: Vec<&Diagnostic> = Vec::new();
- for d in diags {
- if d.span.is_some() {
- spanned.push(d);
- } else {
- unspanned.push(d);
- }
- }
- if !spanned.is_empty() {
- let mut builder = SnippetBuilder::new(src);
- for d in spanned {
- let span = d.span.as_ref().expect("spanned");
- let ab = match d.level {
- DiagLevel::Error => {
- builder.error(Text::fragment(d.message.clone(), Formatting::default()))
- }
- DiagLevel::Warning => {
- builder.warning(Text::fragment(d.message.clone(), Formatting::default()))
- }
- };
- ab.range(span.range()).build();
- }
- out.push_str(&hi_doc::source_to_ansi(&builder.build()));
- }
- for d in unspanned {
- let prefix = match d.level {
- DiagLevel::Error => "error",
- DiagLevel::Warning => "warning",
- };
- writeln!(out, "{prefix}: {}", d.message).expect("fmt");
- }
- out
-}
-
pub struct AnalysisReport {
pub lir: LExpr,
pub root_shape: ClosureShape,
@@ -2011,16 +1969,63 @@
#[cfg(test)]
mod tests {
- use std::fs;
+ #[test]
+ #[cfg(not(feature = "exp-null-coaelse"))]
+ fn snapshots() {
+ use std::fs;
- use insta::{assert_snapshot, glob};
- use jrsonnet_ir::Source;
+ use insta::{assert_snapshot, glob};
+ use jrsonnet_ir::Source;
- use super::*;
+ use super::*;
- #[test]
- #[cfg(not(feature = "exp-null-coaelse"))]
- fn snapshots() {
+ fn render_diagnostics(src: &str, diags: &[Diagnostic]) -> String {
+ use std::fmt::Write;
+
+ use hi_doc::{Formatting, SnippetBuilder, Text};
+
+ let mut out = String::new();
+ let mut unspanned = Vec::new();
+ let mut spanned: Vec<&Diagnostic> = Vec::new();
+ for d in diags {
+ if d.span.is_some() {
+ spanned.push(d);
+ } else {
+ unspanned.push(d);
+ }
+ }
+ if !spanned.is_empty() {
+ let mut builder = SnippetBuilder::new(src);
+ for d in spanned {
+ let span = d.span.as_ref().expect("spanned");
+ let ab = match d.level {
+ DiagLevel::Error => {
+ builder.error(Text::fragment(d.message.clone(), Formatting::default()))
+ }
+ DiagLevel::Warning => builder
+ .warning(Text::fragment(d.message.clone(), Formatting::default())),
+ };
+ ab.range(span.range()).build();
+ }
+ out.push_str(&hi_doc::source_to_ansi(&builder.build()));
+ }
+ for d in unspanned {
+ let prefix = match d.level {
+ DiagLevel::Error => "error",
+ DiagLevel::Warning => "warning",
+ };
+ writeln!(out, "{prefix}: {}", d.message).expect("fmt");
+ }
+ out
+ }
+ fn fmt_depth(d: u32) -> String {
+ if d == u32::MAX {
+ "none".into()
+ } else {
+ d.to_string()
+ }
+ }
+
glob!("analysis_tests/*.jsonnet", |path| {
let code = fs::read_to_string(path).expect("read test file");
let src = Source::new_virtual("<test>".into(), code.clone().into());
@@ -2041,13 +2046,5 @@
);
assert_snapshot!(rendered);
});
- }
-
- fn fmt_depth(d: u32) -> String {
- if d == u32::MAX {
- "none".into()
- } else {
- d.to_string()
- }
}
}
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -123,9 +123,9 @@
EagerCompspecCaptured,
#[error("array out of bounds: {0} is not within [0,{1})")]
- ArrayBoundsError(isize, u32),
+ ArrayBoundsError(f64, u32),
#[error("string out of bounds: {0} is not within [0,{1})")]
- StringBoundsError(usize, usize),
+ StringBoundsError(f64, u32),
#[error("assert failed: {}", format_empty_str(.0))]
AssertionFailed(IStr),
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -18,12 +18,12 @@
LIndexPart, LObjAsserts, LObjBody, LObjMembers, LSlot,
},
arr::ArrValue,
- bail, error,
+ bail,
error::{ErrorKind::*, suggest_object_fields},
evaluate::{destructure::fill_letrec_binds, operator::evaluate_unary_op},
function::{CallLocation, FuncDesc, FuncVal, prepared::PreparedFuncVal},
in_frame,
- typed::FromUntyped as _,
+ typed::{BoundedUsize, FromUntyped as _},
val::{CachedUnbound, Thunk},
with_state,
};
@@ -193,7 +193,6 @@
}
LExpr::ArrComp(comp) => evaluate_arr_comp(ctx, comp)?,
LExpr::Slice(slice) => {
- use crate::typed::BoundedUsize;
let val = evaluate(ctx.clone(), &slice.value)?;
let indexable = val.into_indexable()?;
let start = slice
@@ -201,26 +200,14 @@
.as_ref()
.map(|e| evaluate(ctx.clone(), e))
.transpose()?
- .map(|v| -> Result<i32> {
- v.as_num()
- .ok_or_else(|| {
- TypeMismatch("slice start", vec![ValType::Num], v.value_type()).into()
- })
- .map(|n| n as i32)
- })
+ .map(|v| -> Result<i32> { i32::from_untyped(v).description("slice start value") })
.transpose()?;
let end = slice
.end
.as_ref()
.map(|e| evaluate(ctx.clone(), e))
.transpose()?
- .map(|v| -> Result<i32> {
- v.as_num()
- .ok_or_else(|| {
- TypeMismatch("slice end", vec![ValType::Num], v.value_type()).into()
- })
- .map(|n| n as i32)
- })
+ .map(|v| -> Result<i32> { i32::from_untyped(v).description("slice end value") })
.transpose()?;
let step = slice
.step
@@ -228,10 +215,7 @@
.map(|e| evaluate(ctx, e))
.transpose()?
.map(|v| -> Result<BoundedUsize<1, { i32::MAX as usize }>> {
- let n = v.as_num().ok_or_else(|| -> crate::Error {
- TypeMismatch("slice step", vec![ValType::Num], v.value_type()).into()
- })?;
- BoundedUsize::new(n as usize).ok_or_else(|| error!("slice step must be >= 1"))
+ BoundedUsize::from_untyped(v).description("slice step value")
})
.transpose()?;
Val::from(indexable.slice(start, end, step)?)
@@ -410,11 +394,9 @@
if n.fract() > f64::EPSILON {
bail!(FractionalIndex)
}
- if n < 0.0 {
- bail!(ArrayBoundsError(
- n as isize, // truncation is fine for error display
- arr.len()
- ));
+ let len = arr.len();
+ if n < 0.0 || n > f64::from(len) {
+ bail!(ArrayBoundsError(n, len));
}
#[expect(
clippy::cast_possible_truncation,
@@ -424,30 +406,30 @@
let i = n as u32;
arr.get(i)
.with_description_src(loc, || format!("element <{i}> access"))?
- .ok_or_else(|| ArrayBoundsError(i as isize, arr.len()))?
+ .ok_or_else(|| ArrayBoundsError(n, len))?
}
(Val::Str(s), Val::Num(idx)) => {
let n = idx.get();
if n.fract() > f64::EPSILON {
bail!(FractionalIndex)
}
- let flat = s.clone().into_flat();
- if n < 0.0 {
- bail!(ArrayBoundsError(
- n as isize, // truncation is fine for error display
- flat.chars().count() as u32
- ));
- }
#[expect(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "n is checked positive, overflow will truncate as expected"
)]
let i = n as usize;
- let Some(char) = flat.chars().nth(i) else {
- bail!(StringBoundsError(i, flat.chars().count()))
- };
- Val::string(char)
+ let flat = s.clone().into_flat();
+ #[allow(clippy::cast_possible_truncation, reason = "string is max 4g")]
+ if n >= 0.0
+ && n <= f64::from(u32::MAX)
+ && let Some(char) = flat.chars().nth(i)
+ {
+ Val::string(char)
+ } else {
+ let len = flat.chars().count();
+ bail!(StringBoundsError(n, len as u32))
+ }
}
#[cfg(feature = "exp-null-coaelse")]
(Val::Null, _) if part.null_coaelse => return Ok(Val::Null),
@@ -566,7 +548,7 @@
let a_ctx = ctx
.pack_captures_sup_this(&members.frame_shape)
.enter(|fill, ctx| {
- fill_letrec_binds(fill, &ctx, &members.locals);
+ fill_letrec_binds(fill, ctx, &members.locals);
});
for field in &members.fields {
evaluate_field_member_static(&mut builder, ctx.clone(), a_ctx.clone(), field)?;
crates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth1use std::{fmt::Display, rc::Rc};23pub(crate) mod conversions;4pub use conversions::*;5use jrsonnet_gcmodule::Acyclic;6pub use jrsonnet_types::{ComplexValType, ValType};7use thiserror::Error;89use crate::{10 Val,11 error::{Error, ErrorKind, Result},12 in_description_frame,13};1415#[derive(Debug, Error, Clone, Acyclic)]16pub enum TypeError {17 #[error("expected {0}, got {1}")]18 ExpectedGot(ComplexValType, ValType),19 #[error("missing property {0} from {1}")]20 MissingProperty(Rc<str>, ComplexValType),21 #[error("every failed from {0}:\n{1}")]22 UnionFailed(ComplexValType, TypeLocErrorList),23 #[error(24 "number out of bounds: {0} not in {start}..{end}",25 start = .1.map(|v|v.to_string()).unwrap_or_default(),26 end = .2.map(|v|v.to_string()).unwrap_or_default(),27 )]28 BoundsFailed(f64, Option<f64>, Option<f64>),29}30impl From<TypeError> for Error {31 fn from(e: TypeError) -> Self {32 ErrorKind::TypeError(e.into()).into()33 }34}3536#[derive(Debug, Clone, Acyclic)]37pub struct TypeLocError(Box<TypeError>, ValuePathStack);38impl From<TypeError> for TypeLocError {39 fn from(e: TypeError) -> Self {40 Self(Box::new(e), ValuePathStack(Vec::new()))41 }42}43impl From<TypeLocError> for Error {44 fn from(e: TypeLocError) -> Self {45 ErrorKind::TypeError(e).into()46 }47}48impl Display for TypeLocError {49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {50 write!(f, "{}", self.0)?;51 if !(self.1).0.is_empty() {52 write!(f, " at {}", self.1)?;53 }54 Ok(())55 }56}5758#[derive(Debug, Clone, Acyclic)]59pub struct TypeLocErrorList(Vec<TypeLocError>);60impl Display for TypeLocErrorList {61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {62 use std::fmt::Write;63 let mut out = String::new();64 for (i, err) in self.0.iter().enumerate() {65 if i != 0 {66 writeln!(f)?;67 }68 out.clear();69 write!(out, "{err}")?;7071 for (i, line) in out.lines().enumerate() {72 if line.trim().is_empty() {73 continue;74 }75 if i == 0 {76 write!(f, " - ")?;77 } else {78 writeln!(f)?;79 write!(f, " ")?;80 }81 write!(f, "{line}")?;82 }83 }84 Ok(())85 }86}8788fn push_type_description(89 error_reason: impl Fn() -> String,90 path: impl Fn() -> ValuePathItem,91 item: impl Fn() -> Result<()>,92) -> Result<()> {93 in_description_frame(error_reason, || match item() {94 Ok(()) => Ok(()),95 Err(mut e) => {96 if let ErrorKind::TypeError(e) = &mut e.error_mut() {97 (e.1).0.push(path());98 }99 Err(e)100 }101 })102}103104// TODO: check_fast for fast path of union type checking105pub trait CheckType {106 fn check(&self, value: &Val) -> Result<()>;107}108109impl CheckType for ValType {110 fn check(&self, value: &Val) -> Result<()> {111 let got = value.value_type();112 if got != *self {113 let loc_error: TypeLocError = TypeError::ExpectedGot((*self).into(), got).into();114 return Err(loc_error.into());115 }116 Ok(())117 }118}119120#[derive(Clone, Debug, Acyclic)]121enum ValuePathItem {122 Field(Rc<str>),123 Index(u64),124}125impl Display for ValuePathItem {126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {127 match self {128 Self::Field(name) => write!(f, ".{name:?}")?,129 Self::Index(idx) => write!(f, "[{idx}]")?,130 }131 Ok(())132 }133}134135#[derive(Clone, Debug, Acyclic)]136struct ValuePathStack(Vec<ValuePathItem>);137impl Display for ValuePathStack {138 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {139 write!(f, "self")?;140 for elem in self.0.iter().rev() {141 write!(f, "{elem}")?;142 }143 Ok(())144 }145}146147impl CheckType for ComplexValType {148 #[allow(clippy::too_many_lines)]149 fn check(&self, value: &Val) -> Result<()> {150 match self {151 Self::Any => Ok(()),152 Self::Simple(t) => t.check(value),153 Self::Char => match value {154 Val::Str(s) if s.len() == 1 || s.clone().into_flat().chars().count() == 1 => Ok(()),155 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),156 },157 Self::BoundedNumber(from, to) => {158 if let Val::Num(n) = value {159 let n = n.get();160 if from.map(|from| from > n).unwrap_or(false)161 || to.map(|to| to < n).unwrap_or(false)162 {163 return Err(TypeError::BoundsFailed(n, *from, *to).into());164 }165 Ok(())166 } else {167 Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())168 }169 }170 Self::Array(elem_type) => match value {171 Val::Arr(a) => {172 for (i, item) in a.iter().enumerate() {173 push_type_description(174 || format!("array index {i}"),175 || ValuePathItem::Index(i as u64),176 || elem_type.check(&item.clone()?),177 )?;178 }179 Ok(())180 }181 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),182 },183 Self::ArrayRef(elem_type) => match value {184 Val::Arr(a) => {185 for (i, item) in a.iter().enumerate() {186 push_type_description(187 || format!("array index {i}"),188 || ValuePathItem::Index(i as u64),189 || elem_type.check(&item.clone()?),190 )?;191 }192 Ok(())193 }194 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),195 },196 Self::AttrsOf(a) => match value {197 Val::Obj(o) => {198 for (_key, value) in o.iter(199 #[cfg(feature = "exp-preserve-order")]200 false,201 ) {202 let value = value?;203 a.check(&value)?;204 }205 Ok(())206 }207 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),208 },209 Self::ObjectRef(elems) => match value {210 Val::Obj(obj) => {211 for (k, v) in *elems {212 if let Some(got_v) = obj.get((*k).into())? {213 push_type_description(214 || format!("property {k}"),215 || ValuePathItem::Field((*k).into()),216 || v.check(&got_v),217 )?;218 } else {219 return Err(220 TypeError::MissingProperty((*k).into(), self.clone()).into()221 );222 }223 }224 Ok(())225 }226 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),227 },228 Self::Union(types) => {229 let mut errors = Vec::new();230 for ty in types {231 match ty.check(value) {232 Ok(()) => {233 return Ok(());234 }235 Err(e) => match e.error() {236 ErrorKind::TypeError(e) => errors.push(e.clone()),237 _ => return Err(e),238 },239 }240 }241 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())242 }243 Self::UnionRef(types) => {244 let mut errors = Vec::new();245 for ty in *types {246 match ty.check(value) {247 Ok(()) => {248 return Ok(());249 }250 Err(e) => match e.error() {251 ErrorKind::TypeError(e) => errors.push(e.clone()),252 _ => return Err(e),253 },254 }255 }256 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())257 }258 Self::Sum(types) => {259 for ty in types {260 ty.check(value)?;261 }262 Ok(())263 }264 Self::SumRef(types) => {265 for ty in *types {266 ty.check(value)?;267 }268 Ok(())269 }270 Self::Lazy(_lazy) => Ok(()),271 }272 }273}1use std::{fmt::Display, rc::Rc};23pub(crate) mod conversions;4pub use conversions::*;5use jrsonnet_gcmodule::Acyclic;6pub use jrsonnet_types::{ComplexValType, ValType};7use thiserror::Error;89use crate::{10 Val,11 error::{Error, ErrorKind, Result},12 in_description_frame,13};1415#[derive(Debug, Error, Clone, Acyclic)]16pub enum TypeError {17 #[error("expected {0}, got {1}")]18 ExpectedGot(ComplexValType, ValType),19 #[error("missing property {0} from {1}")]20 MissingProperty(Rc<str>, ComplexValType),21 #[error("every failed from {0}:\n{1}")]22 UnionFailed(ComplexValType, TypeLocErrorList),23 #[error(24 "number out of bounds: {0} not in {start}..{end}",25 start = .1.map(|v|v.to_string()).unwrap_or_default(),26 end = .2.map(|v|v.to_string()).unwrap_or_default(),27 )]28 BoundsFailed(f64, Option<f64>, Option<f64>),29}30impl From<TypeError> for Error {31 fn from(e: TypeError) -> Self {32 ErrorKind::TypeError(e.into()).into()33 }34}3536#[derive(Debug, Clone, Acyclic)]37pub struct TypeLocError(Box<TypeError>, ValuePathStack);38impl From<TypeError> for TypeLocError {39 fn from(e: TypeError) -> Self {40 Self(Box::new(e), ValuePathStack(Vec::new()))41 }42}43impl From<TypeLocError> for Error {44 fn from(e: TypeLocError) -> Self {45 ErrorKind::TypeError(e).into()46 }47}48impl Display for TypeLocError {49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {50 write!(f, "{}", self.0)?;51 if !(self.1).0.is_empty() {52 write!(f, " at {}", self.1)?;53 }54 Ok(())55 }56}5758#[derive(Debug, Clone, Acyclic)]59pub struct TypeLocErrorList(Vec<TypeLocError>);60impl Display for TypeLocErrorList {61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {62 use std::fmt::Write;63 let mut out = String::new();64 for (i, err) in self.0.iter().enumerate() {65 if i != 0 {66 writeln!(f)?;67 }68 out.clear();69 write!(out, "{err}")?;7071 for (i, line) in out.lines().enumerate() {72 if line.trim().is_empty() {73 continue;74 }75 if i == 0 {76 write!(f, " - ")?;77 } else {78 writeln!(f)?;79 write!(f, " ")?;80 }81 write!(f, "{line}")?;82 }83 }84 Ok(())85 }86}8788fn push_type_description(89 error_reason: impl Fn() -> String,90 path: impl Fn() -> ValuePathItem,91 item: impl Fn() -> Result<()>,92) -> Result<()> {93 in_description_frame(error_reason, || match item() {94 Ok(()) => Ok(()),95 Err(mut e) => {96 if let ErrorKind::TypeError(e) = &mut e.error_mut() {97 (e.1).0.push(path());98 }99 Err(e)100 }101 })102}103104// TODO: check_fast for fast path of union type checking105pub trait CheckType {106 fn check(&self, value: &Val) -> Result<()>;107}108109impl CheckType for ValType {110 fn check(&self, value: &Val) -> Result<()> {111 let got = value.value_type();112 if got != *self {113 let loc_error: TypeLocError = TypeError::ExpectedGot((*self).into(), got).into();114 return Err(loc_error.into());115 }116 Ok(())117 }118}119120#[derive(Clone, Debug, Acyclic)]121enum ValuePathItem {122 Field(Rc<str>),123 Index(u64),124}125impl Display for ValuePathItem {126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {127 match self {128 Self::Field(name) => write!(f, ".{name:?}")?,129 Self::Index(idx) => write!(f, "[{idx}]")?,130 }131 Ok(())132 }133}134135#[derive(Clone, Debug, Acyclic)]136struct ValuePathStack(Vec<ValuePathItem>);137impl Display for ValuePathStack {138 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {139 write!(f, "self")?;140 for elem in self.0.iter().rev() {141 write!(f, "{elem}")?;142 }143 Ok(())144 }145}146147impl CheckType for ComplexValType {148 #[allow(clippy::too_many_lines)]149 fn check(&self, value: &Val) -> Result<()> {150 match self {151 Self::Any => Ok(()),152 Self::Simple(t) => t.check(value),153 Self::Char => match value {154 Val::Str(s) if s.len() == 1 || s.clone().into_flat().chars().count() == 1 => Ok(()),155 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),156 },157 Self::BoundedNumber(from, to) => {158 if let Val::Num(n) = value {159 let n = n.get();160 if from.is_some_and(|from| from > n) || to.is_some_and(|to| to < n) {161 return Err(TypeError::BoundsFailed(n, *from, *to).into());162 }163 Ok(())164 } else {165 Err(TypeError::ExpectedGot(self.clone(), value.value_type()).into())166 }167 }168 Self::Array(elem_type) => match value {169 Val::Arr(a) => {170 for (i, item) in a.iter().enumerate() {171 push_type_description(172 || format!("array index {i}"),173 || ValuePathItem::Index(i as u64),174 || elem_type.check(&item.clone()?),175 )?;176 }177 Ok(())178 }179 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),180 },181 Self::ArrayRef(elem_type) => match value {182 Val::Arr(a) => {183 for (i, item) in a.iter().enumerate() {184 push_type_description(185 || format!("array index {i}"),186 || ValuePathItem::Index(i as u64),187 || elem_type.check(&item.clone()?),188 )?;189 }190 Ok(())191 }192 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),193 },194 Self::AttrsOf(a) => match value {195 Val::Obj(o) => {196 for (_key, value) in o.iter(197 #[cfg(feature = "exp-preserve-order")]198 false,199 ) {200 let value = value?;201 a.check(&value)?;202 }203 Ok(())204 }205 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),206 },207 Self::ObjectRef(elems) => match value {208 Val::Obj(obj) => {209 for (k, v) in *elems {210 if let Some(got_v) = obj.get((*k).into())? {211 push_type_description(212 || format!("property {k}"),213 || ValuePathItem::Field((*k).into()),214 || v.check(&got_v),215 )?;216 } else {217 return Err(218 TypeError::MissingProperty((*k).into(), self.clone()).into()219 );220 }221 }222 Ok(())223 }224 v => Err(TypeError::ExpectedGot(self.clone(), v.value_type()).into()),225 },226 Self::Union(types) => {227 let mut errors = Vec::new();228 for ty in types {229 match ty.check(value) {230 Ok(()) => {231 return Ok(());232 }233 Err(e) => match e.error() {234 ErrorKind::TypeError(e) => errors.push(e.clone()),235 _ => return Err(e),236 },237 }238 }239 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())240 }241 Self::UnionRef(types) => {242 let mut errors = Vec::new();243 for ty in *types {244 match ty.check(value) {245 Ok(()) => {246 return Ok(());247 }248 Err(e) => match e.error() {249 ErrorKind::TypeError(e) => errors.push(e.clone()),250 _ => return Err(e),251 },252 }253 }254 Err(TypeError::UnionFailed(self.clone(), TypeLocErrorList(errors)).into())255 }256 Self::Sum(types) => {257 for ty in types {258 ty.check(value)?;259 }260 Ok(())261 }262 Self::SumRef(types) => {263 for ty in *types {264 ty.check(value)?;265 }266 Ok(())267 }268 Self::Lazy(_lazy) => Ok(()),269 }270 }271}crates/jrsonnet-interner/src/inner.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/inner.rs
+++ b/crates/jrsonnet-interner/src/inner.rs
@@ -161,6 +161,12 @@
// SAFETY: header is initialized
unsafe { (*header).refcnt() }
}
+
+ pub fn len32(&self) -> u32 {
+ let header = Self::header(self);
+ // SAFETY: header is initialized
+ unsafe { (*header).size }
+ }
}
impl Clone for Inner {
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -53,6 +53,10 @@
pub fn cast_bytes(self) -> IBytes {
IBytes(self.0.clone())
}
+
+ pub fn len32(&self) -> u32 {
+ self.0.len32()
+ }
}
impl Deref for IStr {
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -1038,7 +1038,7 @@
}
let e = expr(&mut p)?;
if !p.at_eof() {
- return Err(p.error(format!("expected end of file, got {}", p.current_desc(),)));
+ return Err(p.error(format!("expected end of file, got {}", p.current_desc())));
}
Ok(e)
}
@@ -1051,10 +1051,7 @@
#[cfg(test)]
mod tests {
- use std::fs;
-
- use insta::{assert_snapshot, glob};
- use jrsonnet_ir::{IStr, Source};
+ use insta::assert_snapshot;
use super::*;
@@ -1159,6 +1156,11 @@
#[test]
#[cfg(not(feature = "exp-null-coaelse"))]
fn peg_snapshots() {
+ use std::fs;
+
+ use insta::glob;
+ use jrsonnet_ir::{IStr, Source};
+
glob!("../../jrsonnet-peg-parser/src", "tests/*.jsonnet", |path| {
let input = fs::read_to_string(path).expect("read test file");
let source = Source::new_virtual("<test>".into(), IStr::empty());
crates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-peg-parser/src/lib.rs
+++ b/crates/jrsonnet-peg-parser/src/lib.rs
@@ -433,16 +433,16 @@
#[cfg(test)]
mod tests {
- use std::fs;
+ #[test]
+ #[cfg(not(feature = "exp-null-coaelse"))]
+ fn snapshots() {
+ use std::fs;
- use insta::{assert_snapshot, glob};
- use jrsonnet_ir::{IStr, Source};
+ use insta::{assert_snapshot, glob};
+ use jrsonnet_ir::{IStr, Source};
- use crate::{ParserSettings, parse};
+ use crate::{ParserSettings, parse};
- #[test]
- #[cfg(not(feature = "exp-null-coaelse"))]
- fn snapshots() {
glob!("tests/*.jsonnet", |path| {
let input = fs::read_to_string(path).expect("read test file");
let v = parse(
tests/cpp_test_suite_golden_override/error.array_large_index.jsonnet.goldendiffbeforeafterboth--- a/tests/cpp_test_suite_golden_override/error.array_large_index.jsonnet.golden
+++ b/tests/cpp_test_suite_golden_override/error.array_large_index.jsonnet.golden
@@ -1 +1 @@
-array out of bounds: 4294967295 is not within [0,3)
\ No newline at end of file
+array out of bounds: 18446744073709552000 is not within [0,3)
\ No newline at end of file
tests/go_testdata_golden_override/string_index_negative.jsonnet.goldendiffbeforeafterboth--- a/tests/go_testdata_golden_override/string_index_negative.jsonnet.golden
+++ b/tests/go_testdata_golden_override/string_index_negative.jsonnet.golden
@@ -1 +1 @@
-array out of bounds: -1 is not within [0,4)
\ No newline at end of file
+string out of bounds: -1 is not within [0,4)
\ No newline at end of file