-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Option field causes C error when struct embeds multiple other structs #19441
Comments
fn main() {
mut arr := []NodeInterface{}
arr << &HTMLElement{}
arr << &HTMLElement{}
// removing this comparison lets the code compile
println(arr[0] == arr[1])
}
pub interface Element {
NodeInterface
mut:
tag_name string
}
pub interface NodeInterface {
mut:
node_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
}
PS D:\Test\v\tt1> v run .
false |
Because I wanted to make sure the underlying type is passed by reference and not value. Sorry if that's not right. I have a background of primarily Java and JavaScript where everything is references. |
The way you have it I can't cast back to the original type. Changing your main fn, this println is not allowed, fn main() {
mut arr := []NodeInterface{}
arr << &HTMLElement{}
arr << &HTMLElement{}
println(HTMLElement(arr[0]))
} But this is. fn main() {
mut arr := []&NodeInterface{}
arr << &HTMLElement{}
arr << &HTMLElement{}
println(&HTMLElement(arr[0]))
} |
Describe the bug
When struct A embeds struct B and struct C (which has an option field) and struct A is cast to interface A, then comparing the interface A with another interface A will cause a C error.
Reproduction Steps
Expected Behavior
Expected code to compile and print
true
orfalse
Current Behavior
Possible Solution
No response
Additional Information/Context
No response
V version
V full version: V 0.4.1 68cbf27.20bce37
Environment details (OS name and version, etc.)
Important
You can vote for this issue using the 👍 reaction. More votes increase the issue's priority
for developers.
Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.
The text was updated successfully, but these errors were encountered: