From a2ff24c912d90071741bc154bc143bd1c47e1ee7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 11 Mar 2020 05:56:15 +0100 Subject: [PATCH] cgen: reference receiver test --- vlib/v/checker/checker.v | 10 +++++++--- vlib/v/gen/tests/3.c | 7 +++++++ vlib/v/gen/tests/3.vv | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 8a329a674b..1183aa665c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) { diff --git a/vlib/v/gen/tests/3.c b/vlib/v/gen/tests/3.c index 470b125825..91c18fddce 100644 --- a/vlib/v/gen/tests/3.c +++ b/vlib/v/gen/tests/3.c @@ -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){ }; diff --git a/vlib/v/gen/tests/3.vv b/vlib/v/gen/tests/3.vv index ede302921b..2caaa1b963 100644 --- a/vlib/v/gen/tests/3.vv +++ b/vlib/v/gen/tests/3.vv @@ -3,6 +3,10 @@ struct User { name string } +fn (u &User) foo() { + age := u.age +} + fn main() { user := User{} user.age = 10