diff --git a/releasenotes.md b/releasenotes.md index 650c2179f..ac1194238 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -24,6 +24,7 @@ - Filter `$exec` output from `\r`, which otherwise would cause a compiler assert #1867. - Fixes to `"exec" use, including issue when compiling with MinGW. - Correctly check jump table size and be generous when compiling it #1877. +- Fix bug where .min/.max would fail on a distinct int #1888. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 91546efdd..ef940ac9a 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -472,6 +472,7 @@ CondResult sema_check_comp_time_bool(SemaContext *context, Expr *expr) static bool sema_binary_is_expr_lvalue(SemaContext *context, Expr *top_expr, Expr *expr, bool *failed_ref) { + if (expr->expr_kind == EXPR_CT_SUBSCRIPT) return true; switch (expr->expr_kind) { case UNRESOLVED_EXPRS: @@ -4325,7 +4326,7 @@ static inline bool sema_create_const_min(SemaContext *context, Expr *expr, Type } return true; } - else if (type_is_integer(type)) + else if (type_is_integer(flat)) { expr->expr_kind = EXPR_CONST; expr->const_expr.const_kind = CONST_INTEGER; @@ -7557,7 +7558,9 @@ static inline bool sema_expr_analyse_not(SemaContext *context, Expr *expr) static inline bool sema_expr_analyse_ct_incdec(SemaContext *context, Expr *expr, Expr *inner) { - ASSERT_SPAN(expr, inner->expr_kind == EXPR_CT_IDENT); + ASSERT_SPAN(expr, inner->expr_kind == EXPR_CT_IDENT || inner->expr_kind == EXPR_CT_SUBSCRIPT); + + if (inner->expr_kind == EXPR_CT_SUBSCRIPT) TODO Decl *var = inner->ct_ident_expr.decl; Expr *start_value = var->var.init_expr; @@ -7681,7 +7684,7 @@ static inline bool sema_expr_analyse_incdec(SemaContext *context, Expr *expr) if (!sema_expr_check_assign(context, inner, NULL)) return false; // 3. This might be a $foo, if to handle it. - if (inner->expr_kind == EXPR_CT_IDENT) + if (inner->expr_kind == EXPR_CT_IDENT || inner->expr_kind == EXPR_CT_SUBSCRIPT) { return sema_expr_analyse_ct_incdec(context, expr, inner); } diff --git a/test/test_suite/distinct/distinct_max.c3t b/test/test_suite/distinct/distinct_max.c3t new file mode 100644 index 000000000..cd48b09e0 --- /dev/null +++ b/test/test_suite/distinct/distinct_max.c3t @@ -0,0 +1,8 @@ +module test; +distinct Time = long; + +fn void main(String[] args) +{ + Time.min; + Time.max; +} \ No newline at end of file