mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: do not allow copying any map lvalue (#8662)
This commit is contained in:
parent
51c286df5a
commit
01aa09d515
@ -256,7 +256,7 @@ fn (mut context Context) run() {
|
||||
summary[k] = s
|
||||
}
|
||||
// merge current raw results to the previous ones
|
||||
old_oms := context.results[icmd].oms
|
||||
old_oms := context.results[icmd].oms.move()
|
||||
mut new_oms := map[string][]int{}
|
||||
for k, v in m {
|
||||
if old_oms[k].len == 0 {
|
||||
@ -266,7 +266,7 @@ fn (mut context Context) run() {
|
||||
new_oms[k] << v
|
||||
}
|
||||
}
|
||||
context.results[icmd].oms = new_oms
|
||||
context.results[icmd].oms = new_oms.move()
|
||||
// println('')
|
||||
}
|
||||
}
|
||||
@ -276,7 +276,7 @@ fn (mut context Context) run() {
|
||||
for k, v in context.results[icmd].oms {
|
||||
new_full_summary[k] = new_aints(v, context.nmins, context.nmaxs)
|
||||
}
|
||||
context.results[icmd].summary = new_full_summary
|
||||
context.results[icmd].summary = new_full_summary.move()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,12 @@ fn (mut a App) collect_info() {
|
||||
})
|
||||
}
|
||||
if os_kind == 'linux' {
|
||||
info := a.cpu_info()
|
||||
mut cpu_details := ''
|
||||
if cpu_details == '' {
|
||||
cpu_details = info['model name']
|
||||
cpu_details = a.cpu_info('model name')
|
||||
}
|
||||
if cpu_details == '' {
|
||||
cpu_details = info['hardware']
|
||||
cpu_details = a.cpu_info('hardware')
|
||||
}
|
||||
if cpu_details == '' {
|
||||
cpu_details = os.uname().machine
|
||||
@ -61,8 +60,7 @@ fn (mut a App) collect_info() {
|
||||
})
|
||||
if os_kind == 'linux' {
|
||||
os_details = a.get_linux_os_name()
|
||||
info := a.cpu_info()
|
||||
if 'hypervisor' in info['flags'] {
|
||||
if 'hypervisor' in a.cpu_info('flags') {
|
||||
if 'microsoft' in wsl_check {
|
||||
// WSL 2 is a Managed VM and Full Linux Kernel
|
||||
// See https://docs.microsoft.com/en-us/windows/wsl/compare-versions
|
||||
@ -233,16 +231,15 @@ fn (mut a App) get_linux_os_name() string {
|
||||
return os_details
|
||||
}
|
||||
|
||||
fn (mut a App) cpu_info() map[string]string {
|
||||
fn (mut a App) cpu_info(key string) string {
|
||||
if a.cached_cpuinfo.len > 0 {
|
||||
return a.cached_cpuinfo
|
||||
return a.cached_cpuinfo[key]
|
||||
}
|
||||
info := os.exec('cat /proc/cpuinfo') or {
|
||||
return a.cached_cpuinfo
|
||||
return a.cached_cpuinfo[key]
|
||||
}
|
||||
vals := a.parse(info.output, ':')
|
||||
a.cached_cpuinfo = vals
|
||||
return vals
|
||||
a.cached_cpuinfo = a.parse(info.output, ':')
|
||||
return a.cached_cpuinfo[key]
|
||||
}
|
||||
|
||||
fn (mut a App) git_info() string {
|
||||
|
@ -163,8 +163,8 @@ fn fetch_with_method(method Method, url string, _config FetchConfig) ?Response {
|
||||
|
||||
fn build_url_from_fetch(_url string, config FetchConfig) ?string {
|
||||
mut url := urllib.parse(_url) ?
|
||||
params := config.params
|
||||
if params.keys().len == 0 {
|
||||
params := unsafe {config.params}
|
||||
if params.len == 0 {
|
||||
return url.str()
|
||||
}
|
||||
mut pieces := []string{}
|
||||
|
@ -2717,8 +2717,8 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||
assign_stmt.pos)
|
||||
}
|
||||
if left_sym.kind == .map && !c.inside_unsafe && assign_stmt.op in [.assign, .decl_assign]
|
||||
&& right_sym.kind == .map && (left is ast.Ident && !left.is_blank_ident())
|
||||
&& right is ast.Ident {
|
||||
&& right_sym.kind == .map && !right_type.is_ptr() && !left.is_blank_ident()
|
||||
&& right.is_lvalue() {
|
||||
// Do not allow `a = b`
|
||||
c.error('cannot copy map: call `move` or `clone` method first (or use `unsafe`)',
|
||||
right.position())
|
||||
@ -5596,7 +5596,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) table.Type {
|
||||
sub_structs[int(f.typ)] = n
|
||||
}
|
||||
node.fields = fields
|
||||
node.sub_structs = sub_structs
|
||||
node.sub_structs = sub_structs.move()
|
||||
if node.has_where {
|
||||
c.expr(node.where_expr)
|
||||
}
|
||||
@ -5648,7 +5648,7 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) table.Type {
|
||||
sub_structs[int(f.typ)] = n
|
||||
}
|
||||
node.fields = fields
|
||||
node.sub_structs = sub_structs
|
||||
node.sub_structs = sub_structs.move()
|
||||
c.expr(node.db_expr)
|
||||
if node.kind == .update {
|
||||
for expr in node.update_exprs {
|
||||
|
@ -115,7 +115,7 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
||||
out += '/** @namespace $name */\n'
|
||||
}
|
||||
out += 'const $name = (function ('
|
||||
imports := g.namespaces[node.name].imports
|
||||
imports := unsafe {g.namespaces[node.name].imports}
|
||||
for i, key in imports.keys() {
|
||||
if i > 0 {
|
||||
out += ', '
|
||||
|
@ -178,8 +178,8 @@ pub fn mark_used(mut the_table table.Table, pref &pref.Preferences, ast_files []
|
||||
}
|
||||
}
|
||||
|
||||
the_table.used_fns = walker.used_fns
|
||||
the_table.used_consts = walker.used_consts
|
||||
the_table.used_fns = walker.used_fns.move()
|
||||
the_table.used_consts = walker.used_consts.move()
|
||||
|
||||
$if trace_skip_unused ? {
|
||||
eprintln('>> the_table.used_fns: $the_table.used_fns.keys()')
|
||||
|
Loading…
Reference in New Issue
Block a user