1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: reference receiver test

This commit is contained in:
Alexander Medvednikov 2020-03-11 05:56:15 +01:00
parent 75db3e4416
commit a2ff24c912
3 changed files with 18 additions and 3 deletions

View File

@ -310,10 +310,14 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
pub fn (c mut Checker) selector_expr(selector_expr mut ast.SelectorExpr) table.Type {
typ := c.expr(selector_expr.expr)
if typ == table.void_type_idx {
c.error('unknown selector expression', selector_expr.pos)
return table.void_type
}
selector_expr.expr_type = typ
// if selector_expr.field == 'size' {
// println('sel expr line_nr=$selector_expr.pos.line_nr typ=$selector_expr.expr_type')
// }
if selector_expr.field == 'size' {
println('sel expr line_nr=$selector_expr.pos.line_nr typ=$selector_expr.expr_type')
}
typ_sym := c.table.get_type_symbol(typ)
field_name := selector_expr.field
if field := typ_sym.find_field(field_name) {

View File

@ -5,6 +5,13 @@ struct User {
// multi return structs
// end of definitions #endif
void User_foo(User* u);
void User_foo(User* u) {
int age = u->age;
}
int main() {
User user = (User){
};

View File

@ -3,6 +3,10 @@ struct User {
name string
}
fn (u &User) foo() {
age := u.age
}
fn main() {
user := User{}
user.age = 10