Skip to content

Commit ae21217

Browse files
authored
checker: in vls mode, make ensure_type_exists return true (#25695)
1 parent f24d492 commit ae21217

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

vlib/v/checker/checker.v

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5576,7 +5576,7 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke
55765576
fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
55775577
if typ == 0 {
55785578
c.error('unknown type', pos)
5579-
return false
5579+
return c.pref.is_vls
55805580
}
55815581
c.type_level++
55825582
defer {
@@ -5585,7 +5585,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
55855585
if c.type_level > type_level_cutoff_limit {
55865586
c.error('checker: too many levels of Checker.ensure_type_exists calls: ${c.type_level}, probably due to a self referencing type',
55875587
pos)
5588-
return false
5588+
return c.pref.is_vls
55895589
}
55905590
sym := c.table.sym(typ)
55915591
if !c.is_builtin_mod && !sym.is_pub && sym.mod != c.mod && sym.mod != 'main' {
@@ -5602,12 +5602,12 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
56025602
if fn_mod != '' && fn_mod != c.mod && fn_info.func.name != '' && !fn_info.is_anon {
56035603
c.error('function type `${fn_info.func.name}` was declared as private to module `${fn_mod}`, so it can not be used inside module `${c.mod}`',
56045604
pos)
5605-
return false
5605+
return c.pref.is_vls
56065606
}
56075607
} else if sym.mod != '' {
56085608
c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`',
56095609
pos)
5610-
return false
5610+
return c.pref.is_vls
56115611
}
56125612
}
56135613
match sym.kind {
@@ -5621,7 +5621,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
56215621
if sym.language == .v {
56225622
c.error(util.new_suggestion(sym.name, c.table.known_type_names()).say('unknown type `${sym.name}`'),
56235623
pos)
5624-
return false
5624+
return c.pref.is_vls
56255625
} else if sym.language == .c {
56265626
if !c.pref.translated && !c.file.is_translated {
56275627
c.warn(util.new_suggestion(sym.name, c.table.known_type_names()).say('unknown type `${sym.name}` (all virtual C types must be defined, this will be an error soon)'),
@@ -5643,44 +5643,44 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
56435643
'unknown type `${sym.name}`.\nDid you mean `f64`?'
56445644
}
56455645
c.error(msg, pos)
5646-
return false
5646+
return c.pref.is_vls
56475647
}
56485648
}
56495649
.function {
56505650
fn_info := sym.info as ast.FnType
56515651
if !c.ensure_type_exists(fn_info.func.return_type, fn_info.func.return_type_pos) {
5652-
return false
5652+
return c.pref.is_vls
56535653
}
56545654
for param in fn_info.func.params {
56555655
if !c.ensure_type_exists(param.typ, param.type_pos) {
5656-
return false
5656+
return c.pref.is_vls
56575657
}
56585658
}
56595659
}
56605660
.array {
56615661
if !c.ensure_type_exists((sym.info as ast.Array).elem_type, pos) {
5662-
return false
5662+
return c.pref.is_vls
56635663
}
56645664
}
56655665
.array_fixed {
56665666
if !c.ensure_type_exists((sym.info as ast.ArrayFixed).elem_type, pos) {
5667-
return false
5667+
return c.pref.is_vls
56685668
}
56695669
}
56705670
.map {
56715671
info := sym.info as ast.Map
56725672
if !c.ensure_type_exists(info.key_type, pos) {
5673-
return false
5673+
return c.pref.is_vls
56745674
}
56755675
if !c.ensure_type_exists(info.value_type, pos) {
5676-
return false
5676+
return c.pref.is_vls
56775677
}
56785678
}
56795679
.sum_type {
56805680
info := sym.info as ast.SumType
56815681
for concrete_typ in info.concrete_types {
56825682
if !c.ensure_type_exists(concrete_typ, pos) {
5683-
return false
5683+
return c.pref.is_vls
56845684
}
56855685
}
56865686
}
@@ -5690,7 +5690,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
56905690
...pos
56915691
col: pos.col + 5
56925692
}) {
5693-
return false
5693+
return c.pref.is_vls
56945694
}
56955695
}
56965696
}

vlib/v/tests/vls/autocomplete_module_test.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ const test_data = [
135135
cmd: 'v -w -check -json-errors -nocolor -vls-mode -line-info "${text_file}:34:gd^13" ${os.quoted_path(text_file)}'
136136
output: '${mod1_text_file}:19:10'
137137
},
138+
TestData{
139+
method: .definition
140+
cmd: 'v -w -check -json-errors -nocolor -vls-mode -line-info "${text_file}:39:gd^13" ${os.quoted_path(text_file)}'
141+
output: '${mod1_text_file}:50:7'
142+
},
138143
TestData{
139144
method: .did_change
140145
cmd: 'v -w -vls-mode -check -json-errors ${os.quoted_path(text_file)}'
@@ -234,6 +239,14 @@ const test_data = [
234239
"col":2,
235240
"len":0
236241
}
242+
,
243+
{
244+
"path":"${json_errors_text_file}",
245+
"message":"unknown type `main.NotExistStruct`",
246+
"line_nr":38,
247+
"col":11,
248+
"len":0
249+
}
237250
]
238251
'
239252
},

vlib/v/tests/vls/sample_text.vv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ fn main() {
3333
s.PublicAlias1_2{}
3434
s.public_const1
3535
}
36+
37+
// ensure we can jump to `public_fn1()` even in `NotExistStruct` method
38+
fn (mut x NotExistStruct) add(val int) {
39+
s.public_fn1(1)
40+
}

0 commit comments

Comments
 (0)