checker: fix treating C structs with capitalized fields as embeds (#8343)
parent
cb04e6dccc
commit
daff085033
|
@ -2081,7 +2081,8 @@ pub fn (mut c Checker) selector_expr(mut selector_expr ast.SelectorExpr) table.T
|
|||
mut unknown_field_msg := 'type `$sym.name` has no field or method `$field_name`'
|
||||
mut has_field := false
|
||||
mut field := table.Field{}
|
||||
if field_name.len > 0 && field_name[0].is_capital() && sym.info is table.Struct {
|
||||
if field_name.len > 0 && field_name[0].is_capital() && sym.info is table.Struct
|
||||
&& sym.language == .v {
|
||||
// x.Foo.y => access the embedded struct
|
||||
sym_info := sym.info as table.Struct
|
||||
for embed in sym_info.embeds {
|
||||
|
|
|
@ -5,4 +5,5 @@ import mod1
|
|||
fn main() {
|
||||
res := mod1.vadd(1, 2)
|
||||
println(res)
|
||||
assert res == 1003
|
||||
}
|
||||
|
|
|
@ -3,4 +3,8 @@
|
|||
|
||||
int cadd(int a, int b);
|
||||
|
||||
struct MyStruct {
|
||||
int UppercaseField;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,8 +5,13 @@ module mod1
|
|||
|
||||
#include "header.h"
|
||||
|
||||
struct C.MyStruct {
|
||||
UppercaseField int
|
||||
}
|
||||
|
||||
fn C.cadd(int, int) int
|
||||
|
||||
pub fn vadd(a int, b int) int {
|
||||
return 1000 + C.cadd(a,b)
|
||||
x := C.MyStruct{ 100 }
|
||||
return 900 + x.UppercaseField + C.cadd(a, b)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue