bootstrap: cleanup code checking for overflowing int literals, ease forwards compatibility with V versions before ef758a7

This commit is contained in:
Delyan Angelov 2024-05-24 10:30:16 +03:00
parent 5407dbbde7
commit ccfa65aa14
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 6 additions and 14 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}