parser: allow `arr = []` instead of `arr = []string`

pull/2760/head
Alexander Medvednikov 2019-11-14 07:15:17 +03:00
parent 8d4ef822b6
commit 5df5f97daf
2 changed files with 8 additions and 2 deletions

View File

@ -569,6 +569,9 @@ pub fn (v &V) v_files_from_dir(dir string) []string {
// Parses imports, adds necessary libs, and then user files // Parses imports, adds necessary libs, and then user files
pub fn (v mut V) add_v_files_to_compile() { pub fn (v mut V) add_v_files_to_compile() {
mut builtin_files := v.get_builtin_files() mut builtin_files := v.get_builtin_files()
if v.pref.is_bare {
builtin_files = []string
}
// Builtin cache exists? Use it. // Builtin cache exists? Use it.
builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh' builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh'
if v.pref.is_cache && os.file_exists(builtin_vh) { if v.pref.is_cache && os.file_exists(builtin_vh) {

View File

@ -2424,13 +2424,16 @@ fn (p mut Parser) array_init() string {
} }
p.check(.rsbr) p.check(.rsbr)
// type after `]`? (e.g. "[]string") // 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 `[]`') p.error('specify array type: `[]typ` instead of `[]`')
} }
if p.tok == .name && i == 0 { if p.tok == .name && i == 0 {
// vals.len == 0 { // vals.len == 0 {
typ = p.get_type() 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 // ! after array => no malloc and no copy
no_alloc := p.tok == .not no_alloc := p.tok == .not
if no_alloc { if no_alloc {