Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vet, parser: move dynamic const array check from parser into vet #21423

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/tools/vvet/tests/const_dynamic_array_notice.out
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cmd/tools/vvet/tests/prog_without_main_fn.out
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion cmd/tools/vvet/vvet.v
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn (mut vt Vet) stmts(stmts []ast.Stmt) {

fn (mut vt Vet) stmt(stmt ast.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.Return { vt.exprs(stmt.exprs) }
ast.AssertStmt { vt.expr(stmt.expr) }
Expand Down Expand Up @@ -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) {
if !vt.opt.is_verbose {
return
Expand Down
4 changes: 0 additions & 4 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -3891,10 +3891,6 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
return ast.ConstDecl{}
}
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 {
end_comments << p.eat_comments(same_line: true)
}
Expand Down