From fc6a34355d23db90b8999382ccda67e75268a330 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 24 May 2023 21:54:04 -0300 Subject: [PATCH] parser: fix missing sync auto import when only declaring shared type and not using it (#18255) --- vlib/v/checker/tests/sync_receiver_decl.out | 0 vlib/v/checker/tests/sync_receiver_decl.vv | 4 ++++ vlib/v/parser/fn.v | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 vlib/v/checker/tests/sync_receiver_decl.out create mode 100644 vlib/v/checker/tests/sync_receiver_decl.vv diff --git a/vlib/v/checker/tests/sync_receiver_decl.out b/vlib/v/checker/tests/sync_receiver_decl.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vlib/v/checker/tests/sync_receiver_decl.vv b/vlib/v/checker/tests/sync_receiver_decl.vv new file mode 100644 index 0000000000..29f1575bf3 --- /dev/null +++ b/vlib/v/checker/tests/sync_receiver_decl.vv @@ -0,0 +1,4 @@ +struct St {} +fn (shared b St) g() {} + +println('ok') \ No newline at end of file diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index fcbd669109..966e2a6fa2 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -623,6 +623,9 @@ fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInf if rec.is_mut { p.next() // `mut` } + if is_shared { + p.register_auto_import('sync') + } rec_start_pos := p.tok.pos() rec.name = p.check_name() if !rec.is_mut {