From 3e564a2506572db60288a388daabdd913e3d692c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 20 Nov 2019 18:19:13 +0300 Subject: [PATCH] parser: fix register() bug in interfaces --- vlib/compiler/struct.v | 2 +- vlib/compiler/tests/interface_test.v | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/vlib/compiler/struct.v b/vlib/compiler/struct.v index 1428efa29c..c7b4a3b5a9 100644 --- a/vlib/compiler/struct.v +++ b/vlib/compiler/struct.v @@ -166,7 +166,7 @@ fn (p mut Parser) struct_decl() { // } // Check if reserved name field_name_token_idx := p.cur_tok_index() - field_name := if name != 'Option' { p.table.var_cgen_name(p.check_name()) } else { p.check_name() } + field_name := if name != 'Option' && !is_interface { p.table.var_cgen_name(p.check_name()) } else { p.check_name() } /* if !p.first_pass() { p.fgen(strings.repeat(` `, fmt_max_len - field_name.len)) diff --git a/vlib/compiler/tests/interface_test.v b/vlib/compiler/tests/interface_test.v index c37c325058..50af93267b 100644 --- a/vlib/compiler/tests/interface_test.v +++ b/vlib/compiler/tests/interface_test.v @@ -53,3 +53,23 @@ fn test_perform_speak() { } +interface Register { + register() +} + +struct RegTest {a int} + +fn (f RegTest) register() { +} + +fn handle_reg(r Register) { +} + +fn test_register() { + f := RegTest{} + f.register() + handle_reg(f) +} + + +