diff --git a/compiler/builders/ast_to_builder.jou b/compiler/builders/ast_to_builder.jou index 4d06f306..383f4cdf 100644 --- a/compiler/builders/ast_to_builder.jou +++ b/compiler/builders/ast_to_builder.jou @@ -225,6 +225,8 @@ class AstToBuilder: match t->kind: case TypeKind.SignedInteger | TypeKind.UnsignedInteger: new_value = self->builder->add(old_value, self->builder->integer(t, diff)) + case TypeKind.FloatingPoint: + new_value = self->builder->add(old_value, self->builder->cast(self->builder->integer(intType, diff), t)) case TypeKind.Pointer: idx = self->builder->integer(longType, diff) new_value = self->builder->indexed_pointer(old_value, idx) diff --git a/compiler/typecheck/step3_function_and_method_bodies.jou b/compiler/typecheck/step3_function_and_method_bodies.jou index 11a453b7..0d806ad2 100644 --- a/compiler/typecheck/step3_function_and_method_bodies.jou +++ b/compiler/typecheck/step3_function_and_method_bodies.jou @@ -489,7 +489,7 @@ def check_increment_or_decrement(state: State*, expr: AstExpression*) -> Type*: assert False t = typecheck_expression_not_void(state, &expr->operands[0]) - if not t->is_integer_type() and t->kind != TypeKind.Pointer: + if not t->is_number_type() and t->kind != TypeKind.Pointer: msg: byte[500] snprintf(msg, sizeof(msg), bad_type_fmt, t->name) fail(expr->location, msg) diff --git a/tests/should_succeed/plusplus_minusminus.jou b/tests/should_succeed/plusplus_minusminus.jou index 4e476d52..fdd18e49 100644 --- a/tests/should_succeed/plusplus_minusminus.jou +++ b/tests/should_succeed/plusplus_minusminus.jou @@ -32,4 +32,18 @@ def main() -> int: n = 0 printf("%d %d\n", n, ++n) # Output: 0 1 + # float + f = 1.23f + printf("%.2f f=%.2f\n", f++, f) # Output: 1.23 f=2.23 + printf("%.2f f=%.2f\n", f--, f) # Output: 2.23 f=1.23 + printf("%.2f f=%.2f\n", ++f, f) # Output: 2.23 f=2.23 + printf("%.2f f=%.2f\n", --f, f) # Output: 1.23 f=1.23 + + # double + d = 1.23 + printf("%.2f d=%.2f\n", d++, d) # Output: 1.23 d=2.23 + printf("%.2f d=%.2f\n", d--, d) # Output: 2.23 d=1.23 + printf("%.2f d=%.2f\n", ++d, d) # Output: 2.23 d=2.23 + printf("%.2f d=%.2f\n", --d, d) # Output: 1.23 d=1.23 + return 0