fix bootstrap

This commit is contained in:
kbkpbot 2025-09-04 22:44:14 +08:00
parent 16380c44a8
commit f2d174c156
3 changed files with 11 additions and 6 deletions

View file

@ -607,7 +607,8 @@ pub fn (mut a array) delete_last() {
// Alternative: Slices can also be made with [start..end] notation
// Alternative: `.slice_ni()` will always return an array.
fn (a array) slice(start int, _end int) array {
end := if _end == max_int { a.len } else { _end } // max_int
// WARNNING: The is a temp solution for bootstrap!
end := if _end == max_i64 || _end == max_i32 { a.len } else { _end } // max_int
$if !no_bounds_checking {
if start > end {
panic('array.slice: invalid slice index (start>end):' + impl_i64_to_string(i64(start)) +
@ -644,7 +645,8 @@ fn (a array) slice(start int, _end int) array {
// This function always return a valid array.
fn (a array) slice_ni(_start int, _end int) array {
// a.flags.clear(.noslices)
mut end := if _end == max_int { a.len } else { _end } // max_int
// WARNNING: The is a temp solution for bootstrap!
mut end := if _end == max_i64 || _end == max_i32 { a.len } else { _end } // max_int
mut start := _start
if start < 0 {

View file

@ -1165,7 +1165,8 @@ pub fn (s string) split_by_space() []string {
// Example: assert 'ABCD'.substr(1,3) == 'BC'
@[direct_array_access]
pub fn (s string) substr(start int, _end int) string {
end := if _end == max_int { s.len } else { _end } // max_int
// WARNNING: The is a temp solution for bootstrap!
end := if _end == max_i64 || _end == max_i32 { s.len } else { _end } // max_int
$if !no_bounds_checking {
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
panic('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
@ -1205,7 +1206,8 @@ pub fn (s string) substr_unsafe(start int, _end int) string {
// return an error when the index is out of range
@[direct_array_access]
pub fn (s string) substr_with_check(start int, _end int) !string {
end := if _end == max_int { s.len } else { _end } // max_int
// WARNNING: The is a temp solution for bootstrap!
end := if _end == max_i64 || _end == max_i32 { s.len } else { _end } // max_int
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
return error('substr(' + impl_i64_to_string(start) + ', ' + impl_i64_to_string(end) +
') out of bounds (len=' + impl_i64_to_string(s.len) + ')')
@ -1230,7 +1232,8 @@ pub fn (s string) substr_with_check(start int, _end int) !string {
@[direct_array_access]
pub fn (s string) substr_ni(_start int, _end int) string {
mut start := _start
mut end := if _end == max_int { s.len } else { _end } // max_int
// WARNNING: The is a temp solution for bootstrap!
mut end := if _end == max_i64 || _end == max_i32 { s.len } else { _end }
// borders math
if start < 0 {

View file

@ -152,7 +152,7 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
} else if sym.info is ast.ArrayFixed {
g.write('${sym.info.size}')
} else {
g.write('2147483647') // max_int
g.write('${max_int}')
}
g.write(')')