mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check import
in the middle of file error
This commit is contained in:
7
vlib/v/checker/tests/import_middle_err.out
Normal file
7
vlib/v/checker/tests/import_middle_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/import_middle_err.v:5:1: error: `import x` can only be declared at the beginning of the file
|
||||||
|
3 | println('hello, world')
|
||||||
|
4 | }
|
||||||
|
5 | import os
|
||||||
|
| ~~~~~~
|
||||||
|
6 | fn main() {
|
||||||
|
7 | println(time.now())
|
8
vlib/v/checker/tests/import_middle_err.vv
Normal file
8
vlib/v/checker/tests/import_middle_err.vv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import time
|
||||||
|
fn show() {
|
||||||
|
println('hello, world')
|
||||||
|
}
|
||||||
|
import os
|
||||||
|
fn main() {
|
||||||
|
println(time.now())
|
||||||
|
}
|
@ -89,18 +89,15 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
|||||||
stmt = com
|
stmt = com
|
||||||
stmts << stmt
|
stmts << stmt
|
||||||
}
|
}
|
||||||
|
// module
|
||||||
mut mstmt := ast.Stmt{}
|
mut mstmt := ast.Stmt{}
|
||||||
module_decl := p.module_decl()
|
module_decl := p.module_decl()
|
||||||
mstmt = module_decl
|
mstmt = module_decl
|
||||||
stmts << mstmt
|
stmts << mstmt
|
||||||
// imports
|
// imports
|
||||||
/*
|
|
||||||
mut imports := []ast.Import{}
|
|
||||||
for p.tok.kind == .key_import {
|
for p.tok.kind == .key_import {
|
||||||
imports << p.import_stmt()
|
stmts << p.import_stmt()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
// TODO: import only mode
|
|
||||||
for {
|
for {
|
||||||
if p.tok.kind == .eof {
|
if p.tok.kind == .eof {
|
||||||
if p.pref.is_script && !p.pref.is_test && p.mod == 'main' && !have_fn_main(stmts) {
|
if p.pref.is_script && !p.pref.is_test && p.mod == 'main' && !have_fn_main(stmts) {
|
||||||
@ -320,6 +317,7 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
|
|||||||
return p.interface_decl()
|
return p.interface_decl()
|
||||||
}
|
}
|
||||||
.key_import {
|
.key_import {
|
||||||
|
p.error_with_pos('`import x` can only be declared at the beginning of the file', p.tok.position())
|
||||||
return p.import_stmt()
|
return p.import_stmt()
|
||||||
}
|
}
|
||||||
.key_global {
|
.key_global {
|
||||||
|
Reference in New Issue
Block a user