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: fix interface eq method with option and ref(fix #19441) #20201

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Dec 17, 2023

  1. Fixed Option field causes C error when struct embeds multiple other structs #19441
  2. Add tests.
pub interface NodeInterface {
mut:
	node_name string
}

pub interface Element {
	NodeInterface
mut:
	tag_name string
}

pub struct Node {
pub mut:
	node_name string
}

pub struct HTMLElement {
	Node
pub mut:
	tag_name string
}

pub struct HTMLInputElement {
	// removing either one of these embedded structs lets the code compile
	HTMLElement
	PopoverInvokerElement
pub mut:
	value string
}

pub struct PopoverInvokerElement {
pub mut:
	// changing this field to `&Element` lets the code compile
	popover_target_element ?&Element
	popover_target_action  string
}

fn main() {
	mut arr := []&NodeInterface{}
	arr << &HTMLElement{}
	arr << &HTMLElement{}

	// removing this comparison lets the code compile
	println(arr[0] == arr[1])
}

outputs:

true

@shove70 shove70 marked this pull request as draft December 17, 2023 09:38
@shove70 shove70 marked this pull request as ready for review December 18, 2023 04:28
@shove70
Copy link
Contributor Author

shove70 commented Dec 18, 2023

By the way, the problem of repeatedly generating the same eq_method is solved.

interface Any{}

struct Foo {
	field &Any
}

fn main() {
	foo1 := &Any(Foo {
		&Any(1)
	})
	foo2 := &Any(Foo {
		&Any(1)
	})
	
	println(foo1 == foo2)
}

outputs:

Running code...
Can't run code. The server returned an error:
/tmp/v_60000/code.377993553552140351.tmp.c:2181: error: redefinition of 'main__Any_interface_eq'
builder error: 
==================
C error. This should never happen.

@shove70
Copy link
Contributor Author

shove70 commented Dec 18, 2023

@spytheman spy,

This needs to be merged, for the green CI:
vlang/ved#173

thank you! :)

@spytheman
Copy link
Member

This needs to be merged, for the green CI: vlang/ved#173

Done. Thanks for fixing it.

@spytheman spytheman merged commit 17d540e into vlang:master Dec 18, 2023
54 checks passed
@shove70 shove70 deleted the patch-2 branch December 18, 2023 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option field causes C error when struct embeds multiple other structs
2 participants