compiler/vlib: add error for no new vars in loop ("_,_") & remove "." from errors

pull/2103/head
joe-conigliaro 2019-09-26 00:59:50 +10:00 committed by Alexander Medvednikov
parent a124d1f0eb
commit d4bae356ba
10 changed files with 25 additions and 22 deletions

View File

@ -593,7 +593,7 @@ fn (v mut V) add_v_files_to_compile() {
import_path := '$ModPath/vlib/$mod_path'
vfiles := v.v_files_from_dir(import_path)
if vfiles.len == 0 {
verror('cannot import module $mod (no .v files in "$import_path").')
verror('cannot import module $mod (no .v files in "$import_path")')
}
// Add all imports referenced by these libs
for file in vfiles {
@ -613,7 +613,7 @@ fn (v mut V) add_v_files_to_compile() {
import_path := v.find_module_path(mod)
vfiles := v.v_files_from_dir(import_path)
if vfiles.len == 0 {
verror('cannot import module $mod (no .v files in "$import_path").')
verror('cannot import module $mod (no .v files in "$import_path")')
}
// Add all imports referenced by these libs
for file in vfiles {
@ -632,7 +632,7 @@ fn (v mut V) add_v_files_to_compile() {
deps_resolved := dep_graph.resolve()
if !deps_resolved.acyclic {
deps_resolved.display()
verror('Import cycle detected.')
verror('Import cycle detected')
}
// add imports in correct order
for mod in deps_resolved.imports() {

View File

@ -213,7 +213,7 @@ pub fn (v mut V) cc_msvc() {
if !v.pref.is_debug && v.out_name_c != 'v.c' && v.out_name_c != 'v_macos.c' {
os.rm(v.out_name_c)
}
verror('Cannot find MSVC on this OS.')
verror('Cannot find MSVC on this OS')
return
}

View File

@ -354,7 +354,7 @@ fn (p mut Parser) import_statement() {
p.error('bad import format')
}
if p.peek() == .number && p.scanner.text[p.scanner.pos + 1] == `.` {
p.error('bad import format. module/submodule names cannot begin with a number.')
p.error('bad import format. module/submodule names cannot begin with a number')
}
mut mod := p.check_name().trim_space()
mut mod_alias := mod
@ -1291,7 +1291,7 @@ fn ($v.name mut $v.typ) $p.cur_fn.name (...) {
')
}
}
p.error('`$v.name` is immutable.')
p.error('`$v.name` is immutable')
}
if !v.is_changed {
p.mark_var_changed(v)
@ -1379,7 +1379,7 @@ fn (p mut Parser) var_decl() {
for i, name in names {
if name == '_' {
if names.len == 1 {
p.error('no new variables on left side of :=')
p.error('no new variables on left side of `:=`')
}
continue
}
@ -1400,7 +1400,7 @@ fn (p mut Parser) var_decl() {
if names.len > 1 {
if names.len != types.len {
mr_fn := p.cgen.cur_line.find_between('=', '(').trim_space()
p.error('assignment mismatch: ${names.len} variables but `$mr_fn` returns $types.len values.')
p.error('assignment mismatch: ${names.len} variables but `$mr_fn` returns $types.len values')
}
p.gen(';\n')
p.gen('$typ $name = ${mr_var_name}.var_$i')
@ -1599,7 +1599,7 @@ fn (p mut Parser) name_expr() string {
// Variable
for { // TODO remove
if name == '_' {
p.error('cannot use `_` as value.')
p.error('cannot use `_` as value')
}
mut v := p.find_var_check_new_var(name) or { break }
if ptr {
@ -2634,7 +2634,7 @@ fn (p mut Parser) string_expr() {
if fspec == 's' {
//println('custom str F=$cformat | format_specifier: "$fspec" | typ: $typ ')
if typ != 'string' {
p.error('only V strings can be formatted with a :${cformat} format, but you have given "${val}", which has type ${typ}.')
p.error('only V strings can be formatted with a :${cformat} format, but you have given "${val}", which has type ${typ}')
}
args = args.all_before_last('${val}.len, ${val}.str') + '${val}.str'
}
@ -3137,6 +3137,9 @@ fn (p mut Parser) for_st() {
i := p.check_name()
p.check(.comma)
val := p.check_name()
if i == '_' && val == '_' {
p.error('no new variables on the left side of `in`')
}
p.fgen(' ')
p.check(.key_in)
p.fgen(' ')

View File

@ -870,7 +870,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) {
// NOTE: come back here
// if alias in fit.imports && fit.imports[alias] == mod {}
if alias in fit.imports && fit.imports[alias] != mod {
verror('cannot import $mod as $alias: import name $alias already in use in "${fit.file_path}".')
verror('cannot import $mod as $alias: import name $alias already in use in "${fit.file_path}"')
}
if mod.contains('.internal.') {
mod_parts := mod.split('.')
@ -881,7 +881,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) {
}
internal_parent := internal_mod_parts.join('.')
if !fit.module_name.starts_with(internal_parent) {
verror('module $mod can only be imported internally by libs.')
verror('module $mod can only be imported internally by libs')
}
}
fit.imports[alias] = mod

View File

@ -62,7 +62,7 @@ struct B {
mut:
a A
}
.vrepl_temp.v:13:15: `c2` is immutable.
.vrepl_temp.v:13:15: `c2` is immutable
.vrepl_temp.v:16:12: cannot modify immutable field `e` (type `F`)
declare the field with `mut:`
struct F {

View File

@ -5,7 +5,7 @@
module rand
const (
ReadError = error('crypro.rand.read() error reading random bytes.')
ReadError = error('crypro.rand.read() error reading random bytes')
)
// NOTE: temp until we have []bytes(buff)

View File

@ -12,7 +12,7 @@ const (
err_comment_is_delim = error('encoding.csv: comment cannot be the same as delimiter')
err_invalid_delim = error('encoding.csv: invalid delimiter')
err_eof = error('encoding.csv: end of file')
err_invalid_le = error('encoding.csv: could not find any valid line endings.')
err_invalid_le = error('encoding.csv: could not find any valid line endings')
)

View File

@ -133,7 +133,7 @@ pub fn get_module_filename(handle HANDLE) ?string {
return _filename
default:
// Must handled with GetLastError and converted by FormatMessage
return error('Cannot get file name from handle.')
return error('Cannot get file name from handle')
}
}
panic('this should be unreachable') // TODO remove unreachable after loop

View File

@ -56,7 +56,7 @@ pub fn open(name string, level int, mode string) ?zip_ptr {
/* struct zip_t* */_p_zip := zip_ptr(C.zip_open(name.str,
_nlevel, mode.str))
if _p_zip == zip_ptr(0) {
return error('szip: cannot open/create/append new zip archive.')
return error('szip: cannot open/create/append new zip archive')
}
return _p_zip
}
@ -130,7 +130,7 @@ pub fn (zentry mut zip_ptr) name() string {
pub fn (zentry mut zip_ptr) index() ?int {
_index := int(C.zip_entry_index(zentry))
if _index == -1 {
return error('szip: cannot get current index of zip entry.')
return error('szip: cannot get current index of zip entry')
}
return _index // must be check for INVALID_VALUE
}
@ -146,7 +146,7 @@ pub fn (zentry mut zip_ptr) index() ?int {
pub fn (zentry mut zip_ptr) isdir() ?bool {
_isdir := C.zip_entry_isdir(zentry)
if _isdir == -1 {
return error('szip: cannot check entry type.')
return error('szip: cannot check entry type')
}
dir := bool(_isdir) // wtf V , unary lvalue
return dir
@ -227,7 +227,7 @@ pub fn (zentry mut zip_ptr) read_entry() ?voidptr {
mut _bsize := i64(0)
res := C.zip_entry_read(zentry, &_buf, &_bsize)
if res == -1 {
return error('szip: cannot read properly data from entry.')
return error('szip: cannot read properly data from entry')
}
return _buf
}
@ -279,7 +279,7 @@ pub fn (zentry mut zip_ptr) extract_entry(path string) /*?*/bool {
pub fn (zentry mut zip_ptr) total() ?int {
_tentry := int(C.zip_total_entries(zentry))
if _tentry == -1 {
return error('szip: cannot count total entries.')
return error('szip: cannot count total entries')
}
return _tentry
}

View File

@ -154,7 +154,7 @@ fn (am mut AssetManager) include(asset_type string, combine bool) string {
// fn (am mut AssetManager) add(asset_type, file string) ?bool {
fn (am mut AssetManager) add(asset_type, file string) bool {
if !os.file_exists(file) {
// return error('vweb.assets: cannot add asset $file, it does not exist.')
// return error('vweb.assets: cannot add asset $file, it does not exist')
return false
}
asset := Asset{