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

Compiler bug when trying to return an interface-optional with a fallback default value #21660

Closed
dasidiot opened this issue Jun 9, 2024 · 0 comments · Fixed by #21661
Closed
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

@dasidiot
Copy link
Contributor

dasidiot commented Jun 9, 2024

Describe the bug

/tmp/v_1000/v-option-bug.01HZZ86M38ET1YCNSFHJVPHZQ6.tmp.c:13154: error: cannot convert 'struct src__example__IFoo' to 'struct _option_src__example__IFoo'
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

The function in question tries to return a result of the interface directly from the struct, which itself is an optional. If the struct value is not set it invokes a function to create a default. The produced C code does not seem to realize that the value is no longer an optional.

Reproduction Steps

There is a full reproducer here:
https://github.com/dasidiot/v-option-bug

~/src/v-option-bug$ v -cg run .
/tmp/v_1000/v-option-bug.01HZZ86M38ET1YCNSFHJVPHZQ6.tmp.c:13154: error: cannot convert 'struct src__example__IFoo' to 'struct _option_src__example__IFoo'
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

### Expected Behavior

The program should compile without an error.

### Current Behavior

The C compiler fails to convert from the optional form of the interface to the concrete form of an implementation.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### V version

Current V version: V 0.4.6 1af7b7c, timestamp: 2024-06-09 17:52:56 +0300

### Environment details (OS name and version, etc.)

getwd: /home/user/src/v
vexe: /home/user/src/v/v
vexe mtime: 2024-06-09 19:42:11

vroot: OK, value: /home/user/src/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.2
Git vroot status: weekly.2024.22-47-g1af7b7c3
.git/config present: true

CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

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