mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
checker: update error messages (#21097)
This commit is contained in:
parent
556f9f12ce
commit
3e37643e81
@ -3477,7 +3477,7 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
|||||||
mut mcache := vmod.get_cache()
|
mut mcache := vmod.get_cache()
|
||||||
vmod_file_location := mcache.get_by_file(c.file.path)
|
vmod_file_location := mcache.get_by_file(c.file.path)
|
||||||
if vmod_file_location.vmod_file.len == 0 {
|
if vmod_file_location.vmod_file.len == 0 {
|
||||||
c.error('@VMOD_FILE can be used only in projects, that have v.mod file',
|
c.error('@VMOD_FILE can only be used in projects that have a v.mod file',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
vmod_content := os.read_file(vmod_file_location.vmod_file) or { '' }
|
vmod_content := os.read_file(vmod_file_location.vmod_file) or { '' }
|
||||||
@ -3591,7 +3591,8 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
|||||||
} else if node.kind == .unresolved {
|
} else if node.kind == .unresolved {
|
||||||
// first use
|
// first use
|
||||||
if node.tok_kind == .assign && node.is_mut {
|
if node.tok_kind == .assign && node.is_mut {
|
||||||
c.error('`mut` not allowed with `=` (use `:=` to declare a variable)', node.pos)
|
c.error('`mut` is not allowed with `=` (use `:=` to declare a variable)',
|
||||||
|
node.pos)
|
||||||
}
|
}
|
||||||
if mut obj := node.scope.find(node.name) {
|
if mut obj := node.scope.find(node.name) {
|
||||||
match mut obj {
|
match mut obj {
|
||||||
@ -3834,7 +3835,8 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
|||||||
// Lambdas don't support capturing variables yet, so that's the only hint.
|
// Lambdas don't support capturing variables yet, so that's the only hint.
|
||||||
c.error('undefined variable `${node.name}`', node.pos)
|
c.error('undefined variable `${node.name}`', node.pos)
|
||||||
} else {
|
} else {
|
||||||
c.error('`${node.name}` must be added to the capture list for the closure to be used inside',
|
c.add_error_detail('use `fn [${node.name}] () {` instead of `fn () {`')
|
||||||
|
c.error('`${node.name}` must be explictly listed as inherited variable to be used inside a closure',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
return ast.void_type
|
return ast.void_type
|
||||||
|
@ -5,13 +5,14 @@ vlib/v/checker/tests/anon_fn_arg_type_err.vv:6:14: error: use `_` to name an unu
|
|||||||
| ^
|
| ^
|
||||||
7 | return i
|
7 | return i
|
||||||
8 | }
|
8 | }
|
||||||
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: `i` must be added to the capture list for the closure to be used inside
|
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: `i` must be explictly listed as inherited variable to be used inside a closure
|
||||||
5 |
|
5 |
|
||||||
6 | func := fn (i) int {
|
6 | func := fn (i) int {
|
||||||
7 | return i
|
7 | return i
|
||||||
| ^
|
| ^
|
||||||
8 | }
|
8 | }
|
||||||
9 |
|
9 |
|
||||||
|
Details: use `fn [i] () {` instead of `fn () {`
|
||||||
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:3: error: `i` used as value
|
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:3: error: `i` used as value
|
||||||
5 |
|
5 |
|
||||||
6 | func := fn (i) int {
|
6 | func := fn (i) int {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
vlib/v/parser/tests/closure_not_declared.vv:4:9: error: `a` must be added to the capture list for the closure to be used inside
|
vlib/v/parser/tests/closure_not_declared.vv:4:9: error: `a` must be explictly listed as inherited variable to be used inside a closure
|
||||||
2 | a := 1
|
2 | a := 1
|
||||||
3 | f := fn () {
|
3 | f := fn () {
|
||||||
4 | print(a)
|
4 | print(a)
|
||||||
| ^
|
| ^
|
||||||
5 | }
|
5 | }
|
||||||
6 | f()
|
6 | f()
|
||||||
|
Details: use `fn [a] () {` instead of `fn () {`
|
||||||
vlib/v/parser/tests/closure_not_declared.vv:4:3: error: `print` can not print void expressions
|
vlib/v/parser/tests/closure_not_declared.vv:4:3: error: `print` can not print void expressions
|
||||||
2 | a := 1
|
2 | a := 1
|
||||||
3 | f := fn () {
|
3 | f := fn () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user