mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
vet, parser: move dynamic const array check from parser into vet (#21423)
This commit is contained in:
parent
387af74302
commit
8e7a6e3640
@ -1 +1 @@
|
|||||||
cmd/tools/vvet/tests/const_dynamic_array_notice.vv:1: notice: use a fixed array, instead of a dynamic one
|
cmd/tools/vvet/tests/const_dynamic_array_notice.vv:1: notice: Use a fixed array instead of a dynamic one
|
||||||
|
@ -1 +1 @@
|
|||||||
cmd/tools/vvet/tests/prog_without_main_fn.vv:1: notice: use a fixed array, instead of a dynamic one
|
cmd/tools/vvet/tests/prog_without_main_fn.vv:1: notice: Use a fixed array instead of a dynamic one
|
||||||
|
@ -262,7 +262,7 @@ fn (mut vt Vet) stmts(stmts []ast.Stmt) {
|
|||||||
|
|
||||||
fn (mut vt Vet) stmt(stmt ast.Stmt) {
|
fn (mut vt Vet) stmt(stmt ast.Stmt) {
|
||||||
match stmt {
|
match stmt {
|
||||||
ast.ConstDecl { vt.exprs(stmt.fields.map(it.expr)) }
|
ast.ConstDecl { vt.const_decl(stmt) }
|
||||||
ast.ExprStmt { vt.expr(stmt.expr) }
|
ast.ExprStmt { vt.expr(stmt.expr) }
|
||||||
ast.Return { vt.exprs(stmt.exprs) }
|
ast.Return { vt.exprs(stmt.exprs) }
|
||||||
ast.AssertStmt { vt.expr(stmt.expr) }
|
ast.AssertStmt { vt.expr(stmt.expr) }
|
||||||
@ -310,6 +310,16 @@ fn (mut vt Vet) expr(expr ast.Expr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut vt Vet) const_decl(stmt ast.ConstDecl) {
|
||||||
|
for field in stmt.fields {
|
||||||
|
if field.expr is ast.ArrayInit && !field.expr.is_fixed {
|
||||||
|
vt.notice('Use a fixed array instead of a dynamic one', field.expr.pos.line_nr,
|
||||||
|
.unknown)
|
||||||
|
}
|
||||||
|
vt.expr(field.expr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn (vt &Vet) vprintln(s string) {
|
fn (vt &Vet) vprintln(s string) {
|
||||||
if !vt.opt.is_verbose {
|
if !vt.opt.is_verbose {
|
||||||
return
|
return
|
||||||
|
@ -3891,10 +3891,6 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
|||||||
return ast.ConstDecl{}
|
return ast.ConstDecl{}
|
||||||
}
|
}
|
||||||
expr := p.expr(0)
|
expr := p.expr(0)
|
||||||
if expr is ast.ArrayInit && !expr.is_fixed && p.pref.is_vet {
|
|
||||||
p.vet_notice('use a fixed array, instead of a dynamic one', pos.line_nr, vet.FixKind.unknown,
|
|
||||||
.default)
|
|
||||||
}
|
|
||||||
if is_block {
|
if is_block {
|
||||||
end_comments << p.eat_comments(same_line: true)
|
end_comments << p.eat_comments(same_line: true)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user