1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

detect import of non existent modules

This commit is contained in:
joe-conigliaro 2019-07-27 02:24:40 +10:00 committed by Alexander Medvednikov
parent 979917144f
commit 7b95f09f86

View File

@ -919,8 +919,12 @@ fn (v mut V) add_user_v_files() {
// Parse lib imports // Parse lib imports
if v.pref.build_mode == .default_mode { if v.pref.build_mode == .default_mode {
for i := 0; i < v.table.imports.len; i++ { for i := 0; i < v.table.imports.len; i++ {
pkg := v.module_path(v.table.imports[i]) mod := v.table.imports[i]
vfiles := v.v_files_from_dir('$ModPath/vlib/$pkg') mod_path := v.module_path(v.table.imports[i])
vfiles := v.v_files_from_dir('$ModPath/vlib/$mod_path')
if vfiles.len == 0 {
panic('cannot import module $mod, it does not exist.')
}
// Add all imports referenced by these libs // Add all imports referenced by these libs
for file in vfiles { for file in vfiles {
mut p := v.new_parser(file, Pass.imports) mut p := v.new_parser(file, Pass.imports)
@ -931,15 +935,19 @@ fn (v mut V) add_user_v_files() {
} }
else { else {
// TODO this used to crash compiler? // TODO this used to crash compiler?
// for pkg in v.table.imports { // for mod in v.table.imports {
for i := 0; i < v.table.imports.len; i++ { for i := 0; i < v.table.imports.len; i++ {
pkg := v.module_path(v.table.imports[i]) mod := v.table.imports[i]
mod_path := v.module_path(v.table.imports[i])
idir := os.getwd() idir := os.getwd()
mut import_path := '$idir/$pkg' mut import_path := '$idir/$mod_path'
if !os.file_exists(import_path) { if !os.file_exists(import_path) {
import_path = '$v.lang_dir/vlib/$pkg' import_path = '$v.lang_dir/vlib/$mod_path'
} }
vfiles := v.v_files_from_dir(import_path) vfiles := v.v_files_from_dir(import_path)
if vfiles.len == 0 {
panic('cannot import module $mod, it does not exist.')
}
// Add all imports referenced by these libs // Add all imports referenced by these libs
for file in vfiles { for file in vfiles {
mut p := v.new_parser(file, Pass.imports) mut p := v.new_parser(file, Pass.imports)