From 62c80bc2c51d7256758c70cd079a96997ad5dfbd Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 9 Jun 2020 18:49:15 +1000 Subject: [PATCH] parser: add mod list to allow globals by default --- vlib/v/parser/parser.v | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index fa597e58a0..eafe14b337 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1367,10 +1367,16 @@ fn (mut p Parser) return_stmt() ast.Return { } } +const( + // modules which allow globals by default + global_enabled_mods = ['rand'] +) + // left hand side of `=` or `:=` in `a,b,c := 1,2,3` fn (mut p Parser) global_decl() ast.GlobalDecl { if !p.pref.translated && !p.pref.is_livemain && !p.builtin_mod && !p.pref.building_v && - p.mod != 'ui' && p.mod != 'gg2' && p.mod != 'uiold' && !os.getwd().contains('/volt') && !p.pref.enable_globals { + p.mod != 'ui' && p.mod != 'gg2' && p.mod != 'uiold' && !os.getwd().contains('/volt') && + !p.pref.enable_globals && p.mod !in global_enabled_mods { p.error('use `v --enable-globals ...` to enable globals') } start_pos := p.tok.position()