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 erro: wrong sumtype cast function? #20990

Closed
enghitalo opened this issue Mar 10, 2024 · 0 comments · Fixed by #20994
Closed

cgen erro: wrong sumtype cast function? #20990

enghitalo opened this issue Mar 10, 2024 · 0 comments · Fixed by #20994
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Mar 10, 2024

Describe the bug

Reproduction Steps

struct StructType[T] {
mut:
	val T
}

type SumTypes = StructType[string] | []SumTypes | []string | bool | int | string

pub struct Count {
mut:
	total int
}

// count_chars count json sizen whithout new encode
pub fn (mut count Count) count_chars[T](val T) {
	$if T is $sumtype {
		$for v in val.variants {
			if val is v {
				// dump(typeof(val).name)
				count.count_chars(val)
			}
		}
	} $else $if T is $struct {
		count.chars_in_struct(val)
	} $else {
	}
}

// chars_in_struct
fn (mut count Count) chars_in_struct[T](val T) {
	$for field in T.fields {
		va := val.$(field.name)
		count.count_chars(va)  // Not works
		count.count_chars(val.$(field.name)) // Not works
	}
}

fn main() {
	mut count := Count{}
	count.count_chars(StructType[SumTypes]{ val: '' })
	println('ok')
	assert true
}

Expected Behavior

assert pass, print ok

Current Behavior

==================
/tmp/v_1000/a.01HRM75XMWA9WKHPFBFAQVD0EY.tmp.c:13325: error: cannot convert 'struct main__SumTypes' to 'struct string'
...
==================
(Use `v -cg` to print the entire error message)

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

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.4 386bd77

Environment details (OS name and version, etc.)

Linux

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 Mar 10, 2024
@felipensp felipensp self-assigned this Mar 10, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants