parser: check `import` in the middle of file error
parent
76eec7b6ea
commit
7f69c2fbf5
|
@ -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())
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue