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

cgen: V auto functions is not working in Sumtype variants declaration #22366

Open
enghitalo opened this issue Sep 30, 2024 · 0 comments · May be fixed by #22368
Open

cgen: V auto functions is not working in Sumtype variants declaration #22366

enghitalo opened this issue Sep 30, 2024 · 0 comments · May be fixed by #22368
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Sep 30, 2024

Describe the bug

cgen Error

Reproduction Steps

module main

struct Chacabum {
	a int
}

type SumType = Chacabum | int | string


fn (v SumType) cast[T](val T) string {

	mut res := 'lala'

	$for variant_value in v.variants {
		if v is variant_value {
			// println(v) // ok
			// println('v: ${v.str()}') // ok
			// println('v: ${v}') // not ok <-----------------------------------------------------------------
			// return v // ok
			// res = v.str() // ok
			// res = 'v: ${v.str()}' // ok
			res = 'v: ${v}' // not ok <-----------------------------------------------------------------
		}
	}

	return res

}

fn main() {
	assert SumType(1).cast[int](1) == 'v: 1'
}

Expected Behavior

assert SumType(1).cast[int](1) == 'v: 1' pass

Current Behavior

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/call_methods_at_comptime2.01J91SAWTKJPEVTEFH0X1S8VT4.tmp.c:13382: error: cannot convert 'struct main__Chacabum' to 'unsigned char *'
=================================================================
(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 .

Possible Solution

make res = 'v: ${v}' works as res = 'v: ${v.str()}'?

Additional Information/Context

No response

V version

V 0.4.8 aa3ab3f

Environment details (OS name and version, etc.)

Ubuntu

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.

@enghitalo enghitalo added the Bug This tag is applied to issues which reports bugs. label Sep 30, 2024
@esquerbatua esquerbatua added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Sep 30, 2024
@felipensp felipensp self-assigned this Sep 30, 2024
@felipensp felipensp linked a pull request Sep 30, 2024 that will close this issue
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. Status: Confirmed This bug has been confirmed to be valid by a contributor. 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