compiler/vlib: add error for no new vars in loop ("_,_") & remove "." from errors
parent
a124d1f0eb
commit
d4bae356ba
|
@ -593,7 +593,7 @@ fn (v mut V) add_v_files_to_compile() {
|
||||||
import_path := '$ModPath/vlib/$mod_path'
|
import_path := '$ModPath/vlib/$mod_path'
|
||||||
vfiles := v.v_files_from_dir(import_path)
|
vfiles := v.v_files_from_dir(import_path)
|
||||||
if vfiles.len == 0 {
|
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
|
// Add all imports referenced by these libs
|
||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
|
@ -613,7 +613,7 @@ fn (v mut V) add_v_files_to_compile() {
|
||||||
import_path := v.find_module_path(mod)
|
import_path := v.find_module_path(mod)
|
||||||
vfiles := v.v_files_from_dir(import_path)
|
vfiles := v.v_files_from_dir(import_path)
|
||||||
if vfiles.len == 0 {
|
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
|
// Add all imports referenced by these libs
|
||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
|
@ -632,7 +632,7 @@ fn (v mut V) add_v_files_to_compile() {
|
||||||
deps_resolved := dep_graph.resolve()
|
deps_resolved := dep_graph.resolve()
|
||||||
if !deps_resolved.acyclic {
|
if !deps_resolved.acyclic {
|
||||||
deps_resolved.display()
|
deps_resolved.display()
|
||||||
verror('Import cycle detected.')
|
verror('Import cycle detected')
|
||||||
}
|
}
|
||||||
// add imports in correct order
|
// add imports in correct order
|
||||||
for mod in deps_resolved.imports() {
|
for mod in deps_resolved.imports() {
|
||||||
|
|
|
@ -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' {
|
if !v.pref.is_debug && v.out_name_c != 'v.c' && v.out_name_c != 'v_macos.c' {
|
||||||
os.rm(v.out_name_c)
|
os.rm(v.out_name_c)
|
||||||
}
|
}
|
||||||
verror('Cannot find MSVC on this OS.')
|
verror('Cannot find MSVC on this OS')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -354,7 +354,7 @@ fn (p mut Parser) import_statement() {
|
||||||
p.error('bad import format')
|
p.error('bad import format')
|
||||||
}
|
}
|
||||||
if p.peek() == .number && p.scanner.text[p.scanner.pos + 1] == `.` {
|
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 := p.check_name().trim_space()
|
||||||
mut mod_alias := mod
|
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 {
|
if !v.is_changed {
|
||||||
p.mark_var_changed(v)
|
p.mark_var_changed(v)
|
||||||
|
@ -1379,7 +1379,7 @@ fn (p mut Parser) var_decl() {
|
||||||
for i, name in names {
|
for i, name in names {
|
||||||
if name == '_' {
|
if name == '_' {
|
||||||
if names.len == 1 {
|
if names.len == 1 {
|
||||||
p.error('no new variables on left side of :=')
|
p.error('no new variables on left side of `:=`')
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1400,7 +1400,7 @@ fn (p mut Parser) var_decl() {
|
||||||
if names.len > 1 {
|
if names.len > 1 {
|
||||||
if names.len != types.len {
|
if names.len != types.len {
|
||||||
mr_fn := p.cgen.cur_line.find_between('=', '(').trim_space()
|
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(';\n')
|
||||||
p.gen('$typ $name = ${mr_var_name}.var_$i')
|
p.gen('$typ $name = ${mr_var_name}.var_$i')
|
||||||
|
@ -1599,7 +1599,7 @@ fn (p mut Parser) name_expr() string {
|
||||||
// Variable
|
// Variable
|
||||||
for { // TODO remove
|
for { // TODO remove
|
||||||
if name == '_' {
|
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 }
|
mut v := p.find_var_check_new_var(name) or { break }
|
||||||
if ptr {
|
if ptr {
|
||||||
|
@ -2634,7 +2634,7 @@ fn (p mut Parser) string_expr() {
|
||||||
if fspec == 's' {
|
if fspec == 's' {
|
||||||
//println('custom str F=$cformat | format_specifier: "$fspec" | typ: $typ ')
|
//println('custom str F=$cformat | format_specifier: "$fspec" | typ: $typ ')
|
||||||
if typ != 'string' {
|
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'
|
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()
|
i := p.check_name()
|
||||||
p.check(.comma)
|
p.check(.comma)
|
||||||
val := p.check_name()
|
val := p.check_name()
|
||||||
|
if i == '_' && val == '_' {
|
||||||
|
p.error('no new variables on the left side of `in`')
|
||||||
|
}
|
||||||
p.fgen(' ')
|
p.fgen(' ')
|
||||||
p.check(.key_in)
|
p.check(.key_in)
|
||||||
p.fgen(' ')
|
p.fgen(' ')
|
||||||
|
|
|
@ -870,7 +870,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) {
|
||||||
// NOTE: come back here
|
// NOTE: come back here
|
||||||
// if alias in fit.imports && fit.imports[alias] == mod {}
|
// if alias in fit.imports && fit.imports[alias] == mod {}
|
||||||
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.') {
|
if mod.contains('.internal.') {
|
||||||
mod_parts := mod.split('.')
|
mod_parts := mod.split('.')
|
||||||
|
@ -881,7 +881,7 @@ fn (fit mut FileImportTable) register_alias(alias string, mod string) {
|
||||||
}
|
}
|
||||||
internal_parent := internal_mod_parts.join('.')
|
internal_parent := internal_mod_parts.join('.')
|
||||||
if !fit.module_name.starts_with(internal_parent) {
|
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
|
fit.imports[alias] = mod
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct B {
|
||||||
mut:
|
mut:
|
||||||
a A
|
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`)
|
.vrepl_temp.v:16:12: cannot modify immutable field `e` (type `F`)
|
||||||
declare the field with `mut:`
|
declare the field with `mut:`
|
||||||
struct F {
|
struct F {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
module rand
|
module rand
|
||||||
|
|
||||||
const (
|
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)
|
// NOTE: temp until we have []bytes(buff)
|
||||||
|
|
|
@ -12,7 +12,7 @@ const (
|
||||||
err_comment_is_delim = error('encoding.csv: comment cannot be the same as delimiter')
|
err_comment_is_delim = error('encoding.csv: comment cannot be the same as delimiter')
|
||||||
err_invalid_delim = error('encoding.csv: invalid delimiter')
|
err_invalid_delim = error('encoding.csv: invalid delimiter')
|
||||||
err_eof = error('encoding.csv: end of file')
|
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')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ pub fn get_module_filename(handle HANDLE) ?string {
|
||||||
return _filename
|
return _filename
|
||||||
default:
|
default:
|
||||||
// Must handled with GetLastError and converted by FormatMessage
|
// 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
|
panic('this should be unreachable') // TODO remove unreachable after loop
|
||||||
|
|
|
@ -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,
|
/* struct zip_t* */_p_zip := zip_ptr(C.zip_open(name.str,
|
||||||
_nlevel, mode.str))
|
_nlevel, mode.str))
|
||||||
if _p_zip == zip_ptr(0) {
|
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
|
return _p_zip
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn (zentry mut zip_ptr) name() string {
|
||||||
pub fn (zentry mut zip_ptr) index() ?int {
|
pub fn (zentry mut zip_ptr) index() ?int {
|
||||||
_index := int(C.zip_entry_index(zentry))
|
_index := int(C.zip_entry_index(zentry))
|
||||||
if _index == -1 {
|
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
|
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 {
|
pub fn (zentry mut zip_ptr) isdir() ?bool {
|
||||||
_isdir := C.zip_entry_isdir(zentry)
|
_isdir := C.zip_entry_isdir(zentry)
|
||||||
if _isdir == -1 {
|
if _isdir == -1 {
|
||||||
return error('szip: cannot check entry type.')
|
return error('szip: cannot check entry type')
|
||||||
}
|
}
|
||||||
dir := bool(_isdir) // wtf V , unary lvalue
|
dir := bool(_isdir) // wtf V , unary lvalue
|
||||||
return dir
|
return dir
|
||||||
|
@ -227,7 +227,7 @@ pub fn (zentry mut zip_ptr) read_entry() ?voidptr {
|
||||||
mut _bsize := i64(0)
|
mut _bsize := i64(0)
|
||||||
res := C.zip_entry_read(zentry, &_buf, &_bsize)
|
res := C.zip_entry_read(zentry, &_buf, &_bsize)
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
return error('szip: cannot read properly data from entry.')
|
return error('szip: cannot read properly data from entry')
|
||||||
}
|
}
|
||||||
return _buf
|
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 {
|
pub fn (zentry mut zip_ptr) total() ?int {
|
||||||
_tentry := int(C.zip_total_entries(zentry))
|
_tentry := int(C.zip_total_entries(zentry))
|
||||||
if _tentry == -1 {
|
if _tentry == -1 {
|
||||||
return error('szip: cannot count total entries.')
|
return error('szip: cannot count total entries')
|
||||||
}
|
}
|
||||||
return _tentry
|
return _tentry
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
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) {
|
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
|
return false
|
||||||
}
|
}
|
||||||
asset := Asset{
|
asset := Asset{
|
||||||
|
|
Loading…
Reference in New Issue