diff --git a/lib/std/math.simple_random.c3 b/lib/std/math.simple_random.c3 index 97f992404..e1f3774f1 100644 --- a/lib/std/math.simple_random.c3 +++ b/lib/std/math.simple_random.c3 @@ -5,7 +5,7 @@ struct SimpleRandom long seed; } -private const long SIMPLE_RANDOM_MULTIPLIER = 0x5DEECE66Di64; +private const long SIMPLE_RANDOM_MULTIPLIER = 0x5DEECE66D; private const long SIMPLE_RANDOM_ADDEND = 0xB; private const long SIMPLE_RANDOM_MASK = (1i64 << 48) - 1; diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index 3ed8d5248..17514667c 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -1198,7 +1198,7 @@ Expr *parse_integer(ParseContext *c, Expr *left) } expr_int->const_expr.const_kind = CONST_INTEGER; expr_int->const_expr.is_hex = hex_characters > 0; - Type *type = is_unsigned ? type_cuint : type_cint; + Type *type_base = NULL; expr_int->const_expr.narrowable = !type_bits; if (type_bits) { @@ -1241,16 +1241,31 @@ Expr *parse_integer(ParseContext *c, Expr *left) if (type_bits && !is_power_of_two((uint64_t)type_bits)) type_bits = (int)next_highest_power_of_2((uint32_t)type_bits); } if (type_bits) expr_int->const_expr.is_hex = false; - if (!type_bits) - { - type_bits = (int)type_size(type) * 8; - } if (type_bits) { - type = is_unsigned ? type_int_unsigned_by_bitsize((unsigned)type_bits) : type_int_signed_by_bitsize((unsigned)type_bits); + type_base = is_unsigned ? type_int_unsigned_by_bitsize((unsigned)type_bits) + : type_int_signed_by_bitsize((unsigned)type_bits); } - expr_int->const_expr.ixx = (Int) { i, type->type_kind }; - if (!int_fits(expr_int->const_expr.ixx, type->type_kind)) + else + { + int min_bits = type_size(type_cint) * 8; + Int test = { .i = i }; + for (int type_kind = 0; type_kind < 5; type_kind++) + { + TypeKind kind = (is_unsigned ? TYPE_U8 : TYPE_I8) + type_kind; + int bitsize = type_kind_bitsize(kind); + if (bitsize < min_bits) continue; + test.type = kind; + if (int_fits(test, kind)) + { + type_base = is_unsigned ? type_int_unsigned_by_bitsize(bitsize) : type_int_signed_by_bitsize(bitsize); + break; + } + } + if (!type_base) type_base = is_unsigned ? type_cuint : type_cint; + } + expr_int->const_expr.ixx = (Int) { i, type_base->type_kind }; + if (!int_fits(expr_int->const_expr.ixx, type_base->type_kind)) { unsigned radix = 10; if (hex_characters) radix = 16; @@ -1268,7 +1283,7 @@ Expr *parse_integer(ParseContext *c, Expr *left) } return poisoned_expr; } - expr_int->type = type; + expr_int->type = type_base; advance(c); return expr_int; } diff --git a/src/version.h b/src/version.h index 6519e6d2f..8576d4426 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.125" \ No newline at end of file +#define COMPILER_VERSION "0.3.126" \ No newline at end of file diff --git a/test/test_suite2/errors/illegal_use_of_optional.c3 b/test/test_suite2/errors/illegal_use_of_optional.c3 index 6d33a20ee..282a4745f 100644 --- a/test/test_suite2/errors/illegal_use_of_optional.c3 +++ b/test/test_suite2/errors/illegal_use_of_optional.c3 @@ -5,7 +5,7 @@ fn void syntaxErrors() if (i + 1) {} // #error: optional, but was 'int!' for (int x = i;;) {} // #error: 'int!' to 'int' for (int x = 0; x < i + 1;) {} // #error: optional, but was 'bool!'. - for (int x = 0; x < 10; x += i + 1) {} // #error: Cannot assign an optional value to a non-optional + for (int x = 0; x < 10; x += i + 1) {} // #error: Cannot assign an an optional value to a non-optional switch (i + 1) // #error: optional, but was 'int!' { default: