diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 59406f2a7..46f20e97c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -9961,7 +9961,9 @@ bool sema_cast_const(Expr *expr) case EXPR_RECAST: if (sema_cast_const(expr->inner_expr)) { + Type *type = expr->type; expr_replace(expr, expr->inner_expr); + expr->type = type; return true; } return false; diff --git a/test/test_suite/cast/cast_rcast.c3 b/test/test_suite/cast/cast_rcast.c3 new file mode 100644 index 000000000..2f310fc27 --- /dev/null +++ b/test/test_suite/cast/cast_rcast.c3 @@ -0,0 +1,19 @@ +module test; +// Issue #1811 +bitstruct Image_Tag : uint +{ + char x1 : 24..31; + char x2 : 16..23; + char x3 : 8..15; + char x4 : 0..7; +} + +distinct Glyph_Format = CInt; +const Glyph_Format GLYPH_FORMAT_BITMAP = (Glyph_Format)Image_Tag {'b', 'i', 't', 's'}; + +fn void main() { + // Error: Implicitly casting 'Image_Tag' to 'Glyph_Format' is not permitted + Glyph_Format format = GLYPH_FORMAT_BITMAP; + // Error: 'Glyph_Format' and 'Image_Tag' are different types and cannot be compared. + assert(format == GLYPH_FORMAT_BITMAP); +} \ No newline at end of file