Skip to content

Commit 8088f46

Browse files
committed
parser: fix parsers producing codegen statements (for [flag] enum MyEnum{}) with mixed scope
1 parent 214853c commit 8088f46

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

vlib/v/parser/parser.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
22
// Use of this source code is governed by an MIT license
33
// that can be found in the LICENSE file.
4+
[has_globals]
45
module parser
56

67
import v.scanner
@@ -89,6 +90,8 @@ mut:
8990
codegen_text string
9091
}
9192

93+
__global codegen_files = []&ast.File{}
94+
9295
// for tests
9396
pub fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt {
9497
mut p := Parser{
@@ -312,8 +315,7 @@ pub fn (mut p Parser) parse() &ast.File {
312315
// codegen
313316
if p.codegen_text.len > 0 && !p.pref.is_fmt {
314317
ptext := 'module ' + p.mod.all_after_last('.') + p.codegen_text
315-
codegen_file := parse_text(ptext, p.file_name, p.table, p.comments_mode, p.pref)
316-
stmts << codegen_file.stmts
318+
codegen_files << parse_text(ptext, p.file_name, p.table, p.comments_mode, p.pref)
317319
}
318320

319321
return &ast.File{
@@ -404,6 +406,10 @@ pub fn parse_files(paths []string, table &ast.Table, pref &pref.Preferences) []&
404406
files << parse_file(path, table, .skip_comments, pref)
405407
timers.show('parse_file $path')
406408
}
409+
if codegen_files.len > 0 {
410+
files << codegen_files
411+
codegen_files.clear()
412+
}
407413
return files
408414
}
409415

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[flag]
2+
pub enum Fill {
3+
crash
4+
}
5+
6+
fn font_path() string {
7+
$if dragonfly {
8+
fonts := ['test', 'test/2']
9+
if true {
10+
return fonts[0]
11+
}
12+
}
13+
return ''
14+
}
15+
16+
fn test_compilation() {
17+
a := Fill.crash
18+
println(a)
19+
assert true
20+
}

0 commit comments

Comments
 (0)