<20240914172056.5063-1-yyp@disroot.org>
It was checking if the source is an integer, not the destination. This made it so all integer-based enums could be cast to any type. Reported at: https://lists.sr.ht/~sircmpwn/hare-users/%3Cd65c8dccf8f704e9fa5bf41cbca9e3dc@disroot.org%3E Signed-off-by: Alexey Yerin <yyp@disroot.org> --- src/types.c | 2 +- tests/26-regression.ha | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types.c b/src/types.c index 154acc7..1cb9b67 100644 --- a/src/types.c +++ b/src/types.c @@ -1052,7 +1052,7 @@ type_is_castable(struct context *ctx, const struct type *to, const struct type * return type_is_integer(ctx, to) ? to_orig : NULL; case STORAGE_ENUM: - return to->storage == STORAGE_ENUM || type_is_integer(ctx, from) + return to->storage == STORAGE_ENUM || type_is_integer(ctx, to) ? to_orig : NULL; case STORAGE_F32: case STORAGE_F64: diff --git a/tests/26-regression.ha b/tests/26-regression.ha index 1c8c074..b64f5fd 100644 --- a/tests/26-regression.ha +++ b/tests/26-regression.ha @@ -248,4 +248,6 @@ export fn main() void = { // as three separate tokens, rather than as a float literal assert(((1, 2), 3). // don't remove this comment 0.0 == 1); + + compile(status::CHECK, "type e = enum { A }; fn f() void = { e::A: bool; };")!; }; -- 2.46.0
<D466I96P5H9R.3F674JE2JG61L@fra02>
<20240914172056.5063-1-yyp@disroot.org>
(view parent)
harec/patches: SUCCESS in 39s [types: Fix enum castability check][0] from [Alexey Yerin][1] [0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/55035 [1]: yyp@disroot.org ✓ #1328032 SUCCESS harec/patches/alpine.yml https://builds.sr.ht/~sircmpwn/job/1328032 ✓ #1328033 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1328033 ✓ #1328034 SUCCESS harec/patches/netbsd.yml https://builds.sr.ht/~sircmpwn/job/1328034 ✓ #1328035 SUCCESS harec/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1328035
<D466I9733B3N.2EQ2948OJF517@fra01>
<20240914172056.5063-1-yyp@disroot.org>
(view parent)
harec/patches: SUCCESS in 39s [types: Fix enum castability check][0] from [Alexey Yerin][1] [0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/55035 [1]: yyp@disroot.org ✓ #1328032 SUCCESS harec/patches/alpine.yml https://builds.sr.ht/~sircmpwn/job/1328032 ✓ #1328033 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1328033 ✓ #1328034 SUCCESS harec/patches/netbsd.yml https://builds.sr.ht/~sircmpwn/job/1328034 ✓ #1328035 SUCCESS harec/patches/openbsd.yml https://builds.sr.ht/~sircmpwn/job/1328035
<D466ZAXDN3GZ.3GBYXWX2DB0OV@d2evs.net>
<20240914172056.5063-1-yyp@disroot.org>
(view parent)
this uncovers a bug with rune enums, which should be fixed before re-applying this: https://lists.sr.ht/~sircmpwn/hare-dev/patches/39048