From 26fb7e0821fff32a8b6cccea0be1bcae0b56e631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CA=87=CA=9E=CA=8Cp?= Date: Tue, 19 Nov 2019 13:58:31 -0800 Subject: [PATCH] compiler: emit Option_ typedef for fn args and struct fields --- vlib/compiler/fn.v | 9 +++++++-- vlib/compiler/struct.v | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 99a8e66d04..bdb8f7c75c 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -368,10 +368,15 @@ fn (p mut Parser) fn_decl() { p.check(.lcbr) //p.fgen_nl() } - // Register ?option type - if typ.starts_with('Option_') { + // Register ?option type for return value and args + if typ.starts_with('Option_') { p.cgen.typedefs << 'typedef Option $typ;' } + for arg in f.args { + if arg.typ.starts_with('Option_') { + p.cgen.typedefs << 'typedef Option $arg.typ;' + } + } // Register function f.typ = typ str_args := f.str_args(p.table) diff --git a/vlib/compiler/struct.v b/vlib/compiler/struct.v index b05bbe7cef..1428efa29c 100644 --- a/vlib/compiler/struct.v +++ b/vlib/compiler/struct.v @@ -196,6 +196,10 @@ fn (p mut Parser) struct_decl() { if field_type == name { p.error_with_token_index( 'cannot embed struct `$name` in itself (field `$field_name`)', field_name_token_idx) } + // Register ?option type + if field_type.starts_with('Option_') { + p.gen_typedef('typedef Option $field_type;') + } p.check_and_register_used_imported_type(field_type) is_atomic := p.tok == .key_atomic if is_atomic {