Skip to content

Commit 16c9bf2

Browse files
authored
vlib,tests: fix array's field initialisation with signed integers (preparation for future 64bit int) (#25324)
1 parent 7e9fbaf commit 16c9bf2

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎vlib/v/checker/containers.v‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,14 @@ fn (mut c Checker) check_array_init_default_expr(mut node ast.ArrayInit) {
328328

329329
fn (mut c Checker) check_array_init_para_type(para string, mut expr ast.Expr, pos token.Pos) {
330330
sym := c.table.final_sym(c.unwrap_generic(c.expr(mut expr)))
331-
if sym.kind !in [.int, .int_literal] {
332-
c.error('array ${para} needs to be an int', pos)
331+
$if new_int ? && (arm64 || amd64 || rv64 || s390x || ppc64le || loongarch64) {
332+
if sym.kind !in [.int, .int_literal, .i64, .i32, .i16, .i8] {
333+
c.error('array ${para} needs to be an int/i64/i32/i16/i8', pos)
334+
}
335+
} $else {
336+
if sym.kind !in [.int, .int_literal, .i32, .i16, .i8] {
337+
c.error('array ${para} needs to be an int/i32/i16/i8', pos)
338+
}
333339
}
334340
if expr is ast.IntegerLiteral {
335341
lit := expr as ast.IntegerLiteral

‎vlib/v/gen/c/testdata/translated/sym.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ struct my_struct {
22
bool active;
33
} my_instance = { true };
44

5-
int ExternalSymbol(char *hello) {
5+
i32 ExternalSymbol(char *hello) {
66
return *hello;
77
}

‎vlib/v/gen/c/testdata/translated/translated_module_actual.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module translated
44
#include "@VMODROOT/sym.c"
55

66
@[c: 'ExternalSymbol']
7-
pub fn external_symbol(&char) int
7+
pub fn external_symbol(&char) i32
88

99
struct C.my_struct {
1010
active bool
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
int ExternalSymbol(char* );
2-
int a = ExternalSymbol("hello");
1+
i32 ExternalSymbol(char* );
2+
i32 a = ExternalSymbol("hello");
33
extern struct my_struct my_instance;

0 commit comments

Comments
 (0)