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

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

This commit is contained in:
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 {