Adjust order in which Bool's constructors are declared in the prelude

True corresponds to Constr=1 and False corresponds to Constr=0; their position in the vector shall reflect that. Note that while this would in principle impact codegen for any other type, it doesn't for bool since we likely never looked up this type definition since it is well-known. It does now as the 'reify' function relies on this. Whoopsie.
This commit is contained in:
KtorZ 2024-02-28 10:09:29 +01:00
parent 14f1025f0b
commit 5272f5ecee
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 62 additions and 34 deletions

View File

@ -82,22 +82,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
// Bool
prelude.types_constructors.insert(
BOOL.to_string(),
vec!["True".to_string(), "False".to_string()],
);
prelude.values.insert(
"True".to_string(),
ValueConstructor::public(
bool(),
ValueConstructorVariant::Record {
module: "".into(),
name: "True".to_string(),
field_map: None::<FieldMap>,
arity: 0,
location: Span::empty(),
constructors_count: 2,
},
),
vec!["False".to_string(), "True".to_string()],
);
prelude.values.insert(
@ -115,6 +100,21 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
),
);
prelude.values.insert(
"True".to_string(),
ValueConstructor::public(
bool(),
ValueConstructorVariant::Record {
module: "".into(),
name: "True".to_string(),
field_map: None::<FieldMap>,
arity: 0,
location: Span::empty(),
constructors_count: 2,
},
),
);
prelude.types.insert(
BOOL.to_string(),
TypeConstructor {

View File

@ -101,38 +101,66 @@ fn any_list(fuzz_a: Fuzzer<a>) -> Fuzzer<List<a>> {
fn any_season() -> Fuzzer<Season> {
any_int
|> map(
|> and_then(
fn(i) {
let n = i % 3
if n == 0 {
Winter { cold: True }
any_bool() |> map(Winter)
} else if n == 1 {
Spring(i)
constant(Spring(i))
} else if n == 2 {
Summer
constant(Summer)
} else {
Fall
constant(Fall)
}
},
)
}
// Properties
pub type Season {
Winter { cold: Bool }
Spring(Int)
Summer
Fall
}
test prop_list(xs via any_list(any_season())) {
xs != [Winter(True)] || xs != [Winter(False)]
}
fn length(xs: List<a>) -> Int {
when xs is {
[] -> 0
[_, ..tail] -> 1 + length(tail)
}
}
fn filter(xs: List<a>, f: fn(a) -> Bool) -> List<a> {
when xs is {
[] ->
[]
[head, ..tail] ->
if f(head) {
[head, ..filter(tail, f)]
} else {
filter(tail, f)
}
}
}
// Properties
pub type Season {
Winter(Bool)
Spring(Int)
Summer
Fall
}
// test prop_is_never_summer(xs via any_list(any_season())) {
// filter(xs, fn(x) { x == Summer }) == []
// }
test prop_is_always_cold_in_winter(xs via any_list(any_season())) {
is_always_cold_in_winter(xs)
}
test prop_is_always_cold_in_winter_2() {
is_always_cold_in_winter([Winter(True)])
}
fn is_always_cold_in_winter(xs: List<Season>) -> Bool {
when xs is {
[Winter(cold), ..tail] -> cold && is_always_cold_in_winter(tail)
_ -> True
}
}