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

Map of fixed array initialisations #22133

Closed
thesombady opened this issue Aug 30, 2024 · 4 comments · Fixed by #22149
Closed

Map of fixed array initialisations #22133

thesombady opened this issue Aug 30, 2024 · 4 comments · Fixed by #22149
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@thesombady
Copy link
Contributor

thesombady commented Aug 30, 2024

Describe the bug

Having a struct with a field of type map[string][VALUE]Struct generates faulty C code.

The snippet breaks at the following line est.mod_files['main'][i] = File{} where switching the index to an integer literal no longer brakes the program.

truct File {
    root string
    path string
}

struct Test {
mut:
    mod_files map[string][5]File
}

fn main() {
    mut test := Test{}
    for i in 0 .. 4 {
        test.mod_files['main'][i] = File{}
    }
    dump(test)
}

Reproduction Steps

module main

struct File {
    root string
    path string
}

struct Test {
mut:
    mod_files map[string][5]File
}

fn main() {
    mut test := Test{}
    for i in 0 .. 4 {
        test.mod_files['main'][i] = File{}
    }
    dump(test)
}

Expected Behavior

The expected behaviour is that one set individual elements of the array.

Current Behavior

The program compiles but provides a C error

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 01fd719

Environment details (OS name and version, etc.)

V full version: V 0.4.7 39e550f.01fd719
OS: macos, macOS, 14.5, 23F79
Processor: 8 cpus, 64bit, little endian, Apple M2

getwd: /Users/andreas/dev/zlang
vexe: /Users/andreas/v/v
vexe mtime: 2024-08-29 18:02:46

vroot: OK, value: /Users/andreas/v
VMODULES: OK, value: /Users/andreas/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.45.1
Git vroot status: weekly.2024.24-338-g01fd7191
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

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.

@thesombady thesombady added the Bug This tag is applied to issues which reports bugs. label Aug 30, 2024
@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Aug 30, 2024
@JalonSolov
Copy link
Contributor

C error happens on Mac.

On Linux, you get a V error of error: constant expression expected on this line:

       test.mod_files['main'][i] = File{}

@thesombady
Copy link
Contributor Author

Spytheman tried it to and did not get a V error. And I believe he said it was on a Windows.

@JalonSolov
Copy link
Contributor

JalonSolov commented Aug 30, 2024

He said he also got the C error. He didn't mention Windows. https://discord.com/channels/592103645835821068/592114487759470596/1278793127242502175

@thesombady
Copy link
Contributor Author

My misstake!

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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants