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

C Error while returning struct ref for interface directly from other method call #21115

Closed
akkinenirajesh opened this issue Mar 27, 2024 · 0 comments · Fixed by #21130
Closed
Assignees
Labels
Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@akkinenirajesh
Copy link

akkinenirajesh commented Mar 27, 2024

V doctor:

V full version: V 0.4.5 22744ce.1e8d1a4
OS: macos, macOS, 13.6.1, 22G313
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz

getwd: /Users/rajesh/dev/buvi
vexe: /Users/rajesh/dev/v/v
vexe mtime: 2024-03-27 13:02:57

vroot: OK, value: /Users/rajesh/dev/v
VMODULES: OK, value: /Users/rajesh/.vmodules
VTMP: OK, value: /tmp/v_502

Git version: git version 2.39.3 (Apple Git-145)
Git vroot status: weekly.2024.13-24-g1e8d1a4d-dirty
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.1.0.2.5)
thirdparty/tcc status: thirdparty-macos-amd64 46662e20

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

struct Node1 {
	data int
}

struct Node2 {
	data int
}

interface INode {
	data int
}

fn make_node(c int) !INode {
	match c {
		1 {
			return make_node1()!
		}
		2 {
			return make_node2()!
		}
		else {
			return error('invalid node type')
		}
	}
}

fn make_node1() !&Node1 {
	return &Node1{
		data: 1
	}
}

fn make_node2() !&Node2 {
	return &Node2{
		data: 2
	}
}

What did you expect to see?

Should compile without C error

What did you see instead?

==================
/tmp/v_502/bugs2.01HT01TZ4ZQR212NCFVRBCMDY3.tmp.c:13076:35: error: indirection requires pointer operand ('main__INode' (aka 'struct main__INode') invalid)
                                _result_ok(&(main__INode[]) { *I_main__Node1_to_Interface_main__INode( (*(main__Node1**)_t2.data)) }, (_result*)(&_t1), sizeof(main__INode));
                                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v_502/bugs2.01HT01TZ4ZQR212NCFVRBCMDY3.tmp.c:13088:35: error: indirection requires pointer operand ('main__INode' (aka 'struct main__INode') invalid)
                                _result_ok(&(main__INode[]) { *I_main__Node2_to_Interface_main__INode( (*(main__Node2**)_t5.data)) }, (_result*)(&_t4), sizeof(main__INode));
                                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
...
==================
(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

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.

@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Mar 28, 2024
@felipensp felipensp self-assigned this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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