Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khalyomede opened this issue Jan 4, 2025 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@khalyomede
Copy link
Contributor

khalyomede commented Jan 4, 2025

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

Huly®: V_0.6-21807

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.

@khalyomede khalyomede added the Bug This tag is applied to issues which reports bugs. label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant