Skip to content

"invalid initializer" C error when iterating on a generic map of string T from a generic function #23376

Description

@khalyomede

Describe the bug

When my function declares a first parameter as a map of string generic, there is a C error. When I remove the generic, no error is generated and the program terminates as expected.

Reproduction Steps

Using the following code snippet there is a C error:

module main

fn validate[T](values map[string]T, rules map[string][]string) ! {
  for key, rule_list in rules {
    value := values[key]! // <------------------
  }
}

fn main() {
  validate({
    "age": 31
  }, {
    "age": [
      "required"
    ]
  }) or {
    eprintln(err.msg())
  }
}

Expected Behavior

The program terminates without errors.

Current Behavior

It displays this C error stack trace:

================== C compilation error (from gcc): ==============
cc: /tmp/v_0/main.01JGSHJTQA2ZR9TN1W7PHK9DRV.tmp.c: In function 'main__validate_T_int':
cc: /tmp/v_0/main.01JGSHJTQA2ZR9TN1W7PHK9DRV.tmp.c:7086:26: error: invalid initializer
cc:  7086 |   Map_string_int value = (*(int*)_t4.data);
cc:       |                          ^
=================================================================

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.9

Environment details (OS name and version, etc.)

V full version: V 0.4.9 4225a34
OS: linux, N/A
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz

getwd: /home/v
vexe: /opt/v/v
vexe mtime: 2024-12-30 03:28:29

vroot: OK, value: /opt/v
VMODULES: OK, value: /root/.vmodules
VTMP: OK, value: /tmp/v_0

env VFLAGS: "-cc gcc"

Git version: git version 2.30.6
Git vroot status: 4225a34 (44 commit(s) behind V master)
.git/config present: true

CC version: cc (Alpine 10.2.1_pre1) 10.2.1 20201203
emcc version: N/A
thirdparty/tcc status: thirdparty-linuxmusl-amd64 a3e24da2

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21807

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions