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

generic enum produces invalid c code #23270

Closed
Le0Developer opened this issue Dec 25, 2024 · 0 comments · Fixed by #23273
Closed

generic enum produces invalid c code #23270

Le0Developer opened this issue Dec 25, 2024 · 0 comments · Fixed by #23273
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@Le0Developer
Copy link
Member

Le0Developer commented Dec 25, 2024

follow up of #23269

V doctor:

V full version: V 0.4.7 62c69e8.caa0c46
OS: macos, macOS, 15.2, 24C101
Processor: 8 cpus, 64bit, little endian, Apple M2

getwd: /Users/leodev/p/v/cluedo
vexe: /Users/leodev/bin/v/v
vexe mtime: 2024-08-26 08:17:23

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

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.34-46-gcaa0c464 (866 commit(s) behind V master)
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.6)
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

What did you do?
./v -g -o vdbg cmd/v && ./vdbg repro.v

import os

fn prompt_enum[T](prompt string) T {
	full_prompt := '${prompt}: '
	for {
		s := os.input_opt(full_prompt) or { continue }
		if x := T.from(s) {
			return x
		}
	}
	panic('unreachable')
}

enum EnumA {
	a
	b
	c
}

enum EnumB {
	x
	y
	z
}

fn main() {
	prompt_enum[EnumA]('Which enum A?')
}

What did you expect to see?

Successful compilation

What did you see instead?

================== C compilation error (from cc): ==============
cc:        |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc: /tmp/v_501/repro.01JFZFD586X9D8C8DGWCD7V5HC.tmp.c:18755:13: error: call to undeclared function 'main__EnumA__static__from'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cc:  18755 |                 if (_t2 = main__EnumA__static__from(s), !_t2.is_error) {
cc:        |                           ^
cc: /tmp/v_501/repro.01JFZFD586X9D8C8DGWCD7V5HC.tmp.c:18755:11: error: assigning to '_result_main__EnumA' (aka 'struct _result_main__EnumA') from incompatible type 'int'
cc:  18755 |                 if (_t2 = main__EnumA__static__from(s), !_t2.is_error) {
cc:        |                         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc: 3 warnings and 2 errors generated.
... (the original output was 16 lines long, and was truncated to 8 lines)
================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
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 .

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-21704

@Le0Developer Le0Developer added the Bug This tag is applied to issues which reports bugs. label Dec 25, 2024
@felipensp felipensp self-assigned this Dec 26, 2024
@felipensp felipensp added Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Dec 26, 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. Generics[T] Bugs/feature requests, that are related to the V generics. 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