mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix parsers producing codegen statements (for [flag] enum MyEnum{}
) with mixed scope
This commit is contained in:
parent
214853c373
commit
8088f462c9
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
[has_globals]
|
||||
module parser
|
||||
|
||||
import v.scanner
|
||||
@ -89,6 +90,8 @@ mut:
|
||||
codegen_text string
|
||||
}
|
||||
|
||||
__global codegen_files = []&ast.File{}
|
||||
|
||||
// for tests
|
||||
pub fn parse_stmt(text string, table &ast.Table, scope &ast.Scope) ast.Stmt {
|
||||
mut p := Parser{
|
||||
@ -312,8 +315,7 @@ pub fn (mut p Parser) parse() &ast.File {
|
||||
// codegen
|
||||
if p.codegen_text.len > 0 && !p.pref.is_fmt {
|
||||
ptext := 'module ' + p.mod.all_after_last('.') + p.codegen_text
|
||||
codegen_file := parse_text(ptext, p.file_name, p.table, p.comments_mode, p.pref)
|
||||
stmts << codegen_file.stmts
|
||||
codegen_files << parse_text(ptext, p.file_name, p.table, p.comments_mode, p.pref)
|
||||
}
|
||||
|
||||
return &ast.File{
|
||||
@ -404,6 +406,10 @@ pub fn parse_files(paths []string, table &ast.Table, pref &pref.Preferences) []&
|
||||
files << parse_file(path, table, .skip_comments, pref)
|
||||
timers.show('parse_file $path')
|
||||
}
|
||||
if codegen_files.len > 0 {
|
||||
files << codegen_files
|
||||
codegen_files.clear()
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
[flag]
|
||||
pub enum Fill {
|
||||
crash
|
||||
}
|
||||
|
||||
fn font_path() string {
|
||||
$if dragonfly {
|
||||
fonts := ['test', 'test/2']
|
||||
if true {
|
||||
return fonts[0]
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
fn test_compilation() {
|
||||
a := Fill.crash
|
||||
println(a)
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue
Block a user