commit aa45d76360d9d97ecdcc03558b1d45ec71813ec8
parent 180703b8bda1bcc214e6097c1758dab6f35f60ba
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 16 Jan 2021 11:52:10 -0500
type store: fix tagged union prohibited assignments
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/type_store.c b/src/type_store.c
@@ -44,7 +44,7 @@ tagged_assignable(struct type_store *store,
to_t = to_t->next;
from_t = from_t->next;
} else {
- from_t = from_t->next;
+ to_t = to_t->next;
}
}
return from_t == NULL;
diff --git a/tests/13-tagged.ha b/tests/13-tagged.ha
@@ -1,3 +1,5 @@
+fn rt::compile(src: str) int;
+
fn measurements() void = {
let x: (u8 | u16 | u32 | u64) = 1337u16;
assert(size((u8 | u16 | u32 | u64)) == size(u64) + size(size));
@@ -48,6 +50,13 @@ fn reduction() void = {
let a: (i8 | i16) = 42i8;
let b: (i16 | i8) = a;
let c: (i8 | i16 | i32) = a;
+ assert(rt::compile(
+ // Cannot assign from more general type
+ "fn test() void = {
+ let a: (i8 | i16 | i32) = 42i8;
+ let b: (i8 | i16) = a;
+ };"
+ ) != 0);
assert(a is i8 && b is i8 && c is i8);
assert(size((i8 | i16 | i32)) == size((i8 | (i16 | i32))));
assert(size(integer) == size(signed));