mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a suggestion for misspelled mod.const_name + a test
This commit is contained in:
parent
b4c529066a
commit
1cf683d482
@ -3395,10 +3395,24 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
|||||||
if c.inside_ct_attr {
|
if c.inside_ct_attr {
|
||||||
c.note('`[if $node.name]` is deprecated. Use `[if $node.name?]` instead',
|
c.note('`[if $node.name]` is deprecated. Use `[if $node.name?]` instead',
|
||||||
node.pos)
|
node.pos)
|
||||||
|
} else {
|
||||||
|
cname_mod := node.name.all_before('.')
|
||||||
|
if cname_mod.len != node.name.len {
|
||||||
|
mut const_names_in_mod := []string{}
|
||||||
|
for _, so in c.table.global_scope.objects {
|
||||||
|
if so is ast.ConstField {
|
||||||
|
if so.mod == cname_mod {
|
||||||
|
const_names_in_mod << so.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.error(util.new_suggestion(node.name, const_names_in_mod).say('undefined ident: `$node.name`'),
|
||||||
|
node.pos)
|
||||||
} else {
|
} else {
|
||||||
c.error('undefined ident: `$node.name`', node.pos)
|
c.error('undefined ident: `$node.name`', node.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if c.table.known_type(node.name) {
|
if c.table.known_type(node.name) {
|
||||||
// e.g. `User` in `json.decode(User, '...')`
|
// e.g. `User` in `json.decode(User, '...')`
|
||||||
return ast.void_type
|
return ast.void_type
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/misspelled_mod_const_should_have_suggestion.vv:3:21: error: undefined ident: `time.secondz`.
|
||||||
|
Did you mean `time.second`?
|
||||||
|
1 | import time
|
||||||
|
2 |
|
||||||
|
3 | time.sleep(1 * time.secondz)
|
||||||
|
| ~~~~~~~
|
@ -0,0 +1,3 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
time.sleep(1 * time.secondz)
|
Loading…
Reference in New Issue
Block a user