diff --git a/crates/typst/src/foundations/array.rs b/crates/typst/src/foundations/array.rs index 27f56194f..b001aa20f 100644 --- a/crates/typst/src/foundations/array.rs +++ b/crates/typst/src/foundations/array.rs @@ -803,8 +803,8 @@ pub struct ToArray(Array); cast! { ToArray, - v: Bytes => Self(v.iter().map(|&b| Value::Int(b.into())).collect()), v: Array => Self(v), + v: Bytes => Self(v.iter().map(|&b| Value::Int(b.into())).collect()), v: Version => Self(v.values().iter().map(|&v| Value::Int(v as i64)).collect()) } diff --git a/crates/typst/src/foundations/float.rs b/crates/typst/src/foundations/float.rs index 723e023bb..ee442a29b 100644 --- a/crates/typst/src/foundations/float.rs +++ b/crates/typst/src/foundations/float.rs @@ -107,6 +107,7 @@ pub struct ToFloat(f64); cast! { ToFloat, + v: f64 => Self(v), v: bool => Self(v as i64 as f64), v: i64 => Self(v as f64), v: Ratio => Self(v.get()), @@ -114,7 +115,6 @@ cast! { parse_float(v.clone().into()) .map_err(|_| eco_format!("invalid float: {}", v))? ), - v: f64 => Self(v), } fn parse_float(s: EcoString) -> Result { diff --git a/crates/typst/src/foundations/int.rs b/crates/typst/src/foundations/int.rs index f7f8c0e88..ef21f7853 100644 --- a/crates/typst/src/foundations/int.rs +++ b/crates/typst/src/foundations/int.rs @@ -229,10 +229,10 @@ pub struct ToInt(i64); cast! { ToInt, + v: i64 => Self(v), v: bool => Self(v as i64), v: f64 => Self(v as i64), v: Str => Self(parse_int(&v).map_err(|_| eco_format!("invalid integer: {}", v))?), - v: i64 => Self(v), } fn parse_int(mut s: &str) -> Result { diff --git a/crates/typst/src/visualize/color.rs b/crates/typst/src/visualize/color.rs index 33d824e18..e22f668c8 100644 --- a/crates/typst/src/visualize/color.rs +++ b/crates/typst/src/visualize/color.rs @@ -1916,8 +1916,8 @@ pub struct ChromaComponent(f32); cast! { ChromaComponent, - v: Ratio => Self((v.get() * 0.4) as f32), v: f64 => Self(v as f32), + v: Ratio => Self((v.get() * 0.4) as f32), } /// An integer or ratio component. diff --git a/tests/typ/bugs/int-constructor.typ b/tests/typ/bugs/int-constructor.typ new file mode 100644 index 000000000..0bdce6121 --- /dev/null +++ b/tests/typ/bugs/int-constructor.typ @@ -0,0 +1,7 @@ +// Test that integer -> integer conversion doesn't do a roundtrip through float. +// Ref: false + +--- +#let x = 9223372036854775800 +#test(type(x), int) +#test(int(x), x) diff --git a/tests/typ/compiler/bytes.typ b/tests/typ/compiler/bytes.typ index 9a26e8265..284ef7739 100644 --- a/tests/typ/compiler/bytes.typ +++ b/tests/typ/compiler/bytes.typ @@ -28,5 +28,5 @@ #bytes((a: 1)) --- -// Error: 8-15 expected bytes, array, or version, found string +// Error: 8-15 expected array, bytes, or version, found string #array("hello") diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ index acd9b2a8d..94a131057 100644 --- a/tests/typ/compute/calc.typ +++ b/tests/typ/compute/calc.typ @@ -53,11 +53,11 @@ #test(calc.round(calc.pi, digits: 2), 3.14) --- -// Error: 6-10 expected boolean, float, string, or integer, found length +// Error: 6-10 expected integer, boolean, float, or string, found length #int(10pt) --- -// Error: 8-13 expected boolean, integer, ratio, string, or float, found type +// Error: 8-13 expected float, boolean, integer, ratio, or string, found type #float(float) ---