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

builder error: Compiler confuses declarations of const expressions when they are located in different files #20970

Closed
ttytm opened this issue Mar 7, 2024 · 0 comments · Fixed by #20973
Assignees
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

@ttytm
Copy link
Member

ttytm commented Mar 7, 2024

Describe the bug

The bug happens when using expressions that result in different types for constants and the consts are declared in different files.

Reproduction Steps

// foo/main.v
import rand

struct MyStruct {
	foo int
}

const my_struct = MyStruct{rand.intn(6) or { panic(err) }}
// No issue when using a single file for the constants.
// const cfg_dir = os.join_path(os.config_dir() or { panic(err) }, 'foo') 

fn main() {
	dump('hello')
}
// foo/config.v
import os

const cfg_dir = os.join_path(os.config_dir() or { panic(err) }, 'foo')
v foo

Expected Behavior

Program is able to compile and run.

Current Behavior

Builder error

==================
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v_501/foo.01HRBP61MACMMT3V4G8Y5RKWV0.tmp.c:22751:13: error: redefinition of '_t1' with a different type: '_result_int' (aka 'struct _result_int') vs '_result_string' (aka 'struct _result_string')
_result_int _t1 = rand__intn(6);
            ^
/tmp/v_501/foo.01HRBP61MACMMT3V4G8Y5RKWV0.tmp.c:22742:16: note: previous definition is here
_result_string _t1 = os__config_dir();
               ^
3 warnings and 1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

Possible Solution

No response

Additional Information/Context

Tested on macOS arm and ubuntu arm.

V version

Environment details (OS name and version, etc.)

V full version: V 0.4.4 790ea2f
OS: macos, macOS, 14.2.1, 23C71
Processor: 8 cpus, 64bit, little endian, Apple M1

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.

@ttytm ttytm added the Bug This tag is applied to issues which reports bugs. label Mar 7, 2024
@felipensp felipensp self-assigned this Mar 7, 2024
@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Mar 7, 2024
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.

2 participants