From ccfa65aa14925b92f5e5844d1f64b5a85091fb3a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 24 May 2024 10:30:16 +0300 Subject: [PATCH] bootstrap: cleanup code checking for overflowing int literals, ease forwards compatibility with V versions before ef758a7 --- vlib/os/os.c.v | 2 +- vlib/v/builder/cc.v | 2 +- vlib/v/checker/assign.v | 8 ++------ vlib/v/checker/checker.v | 8 ++------ 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index 077021f6a1..2a4a56101f 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -1038,7 +1038,7 @@ pub fn last_error() IError { } // Magic constant because zero is used explicitly at times -pub const error_code_not_set = 0x7EFEFEFE +pub const error_code_not_set = int(0x7EFEFEFE) @[params] pub struct SystemError { diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 3db11e2944..47960e374f 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -169,7 +169,7 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { if v.pref.os == .macos && os.exists('/opt/procursus') { ccoptions.linker_flags << '-Wl,-rpath,/opt/procursus/lib' } - mut user_darwin_version := 999_999_999 + mut user_darwin_version := 999_999 mut user_darwin_ppc := false $if macos { user_darwin_version = os.uname().release.split('.')[0].int() diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index 6055193c7f..9b17a7f407 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -211,12 +211,8 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { } if left_type == ast.int_type { if mut right is ast.IntegerLiteral { - mut is_large := right.val.len > 13 - if !is_large && right.val.len > 9 { - val := right.val.i64() - is_large = overflows_i32(val) - } - if is_large { + val := right.val.i64() + if overflows_i32(val) { c.error('overflow in implicit type `int`, use explicit type casting instead', right.pos) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1773b8b991..a419e63879 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1789,12 +1789,8 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) { // Check for int overflow if field.typ == ast.int_type { if mut field.expr is ast.IntegerLiteral { - mut is_large := field.expr.val.len > 13 - if !is_large && field.expr.val.len > 9 { - val := field.expr.val.i64() - is_large = overflows_i32(val) - } - if is_large { + val := field.expr.val.i64() + if overflows_i32(val) { c.error('overflow in implicit type `int`, use explicit type casting instead', field.expr.pos) }