From 236b7b15bbf5503703ae819edb8c281d824c5164 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Sat, 29 Feb 2020 16:32:00 +1100 Subject: [PATCH] v2: handle optional in return stmt in checker --- vlib/v/checker/checker.v | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1ee352f71f..b82cfb214d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -271,6 +271,7 @@ pub fn (c mut Checker) return_stmt(return_stmt ast.Return) { } expected_type := return_stmt.expected_type expected_type_sym := c.table.get_type_symbol(expected_type) + exp_is_optional := table.type_is_optional(expected_type) mut expected_types := [expected_type] if expected_type_sym.kind == .multi_return { mr_info := expected_type_sym.info as table.MultiReturn @@ -284,6 +285,9 @@ pub fn (c mut Checker) return_stmt(return_stmt ast.Return) { if !c.table.check(got_typ, exp_typ) { got_typ_sym := c.table.get_type_symbol(got_typ) exp_typ_sym := c.table.get_type_symbol(exp_typ) + if got_typ_sym.name == 'Option' && exp_is_optional { + continue + } c.error('cannot use `$got_typ_sym.name` as type `$exp_typ_sym.name` in return argument', return_stmt.pos) } }