From 5df5f97daf55da97ceb1915995536a7e1c9472f8 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 14 Nov 2019 07:15:17 +0300 Subject: [PATCH] parser: allow `arr = []` instead of `arr = []string` --- vlib/compiler/main.v | 3 +++ vlib/compiler/parser.v | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 999c34bcd4..dc527c066f 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -569,6 +569,9 @@ pub fn (v &V) v_files_from_dir(dir string) []string { // Parses imports, adds necessary libs, and then user files pub fn (v mut V) add_v_files_to_compile() { mut builtin_files := v.get_builtin_files() + if v.pref.is_bare { + builtin_files = []string + } // Builtin cache exists? Use it. builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh' if v.pref.is_cache && os.file_exists(builtin_vh) { diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index d612d9e338..e8cfb824a4 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2424,13 +2424,16 @@ fn (p mut Parser) array_init() string { } p.check(.rsbr) // type after `]`? (e.g. "[]string") - if p.tok != .name && i == 0 { + if p.tok != .name && i == 0 && !p.expected_type.starts_with('array_') { p.error('specify array type: `[]typ` instead of `[]`') } if p.tok == .name && i == 0 { // vals.len == 0 { typ = p.get_type() - } + } else if p.expected_type.starts_with('array_') { + // allow `known_array = []` + typ = p.expected_type[6..] + } // ! after array => no malloc and no copy no_alloc := p.tok == .not if no_alloc {