From 4988d340b153fd62ebe7bb3724a5911040ec9d65 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 28 May 2020 01:19:03 +0200 Subject: [PATCH] generics: fix method calls --- vlib/v/checker/checker.v | 4 ++-- vlib/v/tests/generics_test.v | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e09c9a5377..084d000d41 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -701,7 +701,7 @@ pub fn (mut c Checker) call_expr(mut call_expr ast.CallExpr) table.Type { pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type { left_type := c.expr(call_expr.left) call_expr.left_type = left_type - left_type_sym := c.table.get_type_symbol(left_type) + left_type_sym := c.table.get_type_symbol(c.unwrap_generic(left_type)) method_name := call_expr.name // TODO: remove this for actual methods, use only for compiler magic // FIXME: Argument count != 1 will break these @@ -1173,7 +1173,7 @@ pub fn (mut c Checker) return_stmt(mut return_stmt ast.Return) { if sym.kind == .multi_return { for t in sym.mr_info().types { got_types << t - } + } } else { got_types << typ } diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index f897f2112d..16b57fbb09 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -56,6 +56,12 @@ mut: foo string } +fn (u User) init() { +} + +fn (c City) init() { +} + fn test_create() { create() create() @@ -204,5 +210,4 @@ fn test_generic_fn_with_variadics(){ p(abc) p('Good','morning','world') } - */