mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
Ranged number abilities are derived and compiled correctly
Closes #5089
This commit is contained in:
parent
63ef4a486f
commit
240c1f35d6
@ -96,7 +96,9 @@ impl FlatDecodable {
|
||||
// by the backend, and the backend treats opaques like structural aliases.
|
||||
_ => Self::from_var(subs, real_var),
|
||||
},
|
||||
Content::RangedNumber(_) => Err(Underivable),
|
||||
Content::RangedNumber(range) => {
|
||||
Self::from_var(subs, range.default_compilation_variable())
|
||||
}
|
||||
//
|
||||
Content::RecursionVar { .. } => Err(Underivable),
|
||||
Content::Error => Err(Underivable),
|
||||
|
@ -131,7 +131,9 @@ impl FlatEncodable {
|
||||
// by the backend, and the backend treats opaques like structural aliases.
|
||||
_ => Self::from_var(subs, real_var),
|
||||
},
|
||||
Content::RangedNumber(_) => Err(Underivable),
|
||||
Content::RangedNumber(range) => {
|
||||
Self::from_var(subs, range.default_compilation_variable())
|
||||
}
|
||||
//
|
||||
Content::RecursionVar { .. } => Err(Underivable),
|
||||
Content::Error => Err(Underivable),
|
||||
|
@ -485,6 +485,25 @@ mod encode_immediate {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn ranged_number() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" imports [Encode, Json] provides [main] to "./platform"
|
||||
|
||||
main =
|
||||
when Str.fromUtf8 (Encode.toBytes [1, 2, 3] Json.toUtf8) is
|
||||
Ok s -> s
|
||||
_ -> "<bad>"
|
||||
"#
|
||||
),
|
||||
RocStr::from(r"[1,2,3]"),
|
||||
RocStr
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! num_immediate {
|
||||
($($num:expr, $typ:ident)*) => {$(
|
||||
#[test]
|
||||
@ -960,6 +979,28 @@ mod decode_immediate {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm"))]
|
||||
fn ranged_number() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" imports [Json] provides [main] to "./platform"
|
||||
|
||||
main =
|
||||
input = Str.toUtf8 "[1,2,3]"
|
||||
expected = [1,2,3]
|
||||
|
||||
actual = Decode.fromBytes input Json.fromUtf8 |> Result.withDefault []
|
||||
|
||||
actual == expected
|
||||
"#
|
||||
),
|
||||
true,
|
||||
bool
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! num_immediate {
|
||||
($($num:expr, $typ:ident)*) => {$(
|
||||
#[test]
|
||||
|
@ -146,6 +146,11 @@ impl NumericRange {
|
||||
.expect("if number doesn't fit, should have been a type error"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Chooses the type variable to compile this ranged number as.
|
||||
pub fn default_compilation_variable(&self) -> Variable {
|
||||
int_lit_width_to_variable(self.default_compilation_width())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user