mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check generic interface missing type parameter (#15344)
This commit is contained in:
parent
161ac3434f
commit
d7a3b866ee
@ -24,6 +24,30 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
|
||||
node.elem_type_pos)
|
||||
}
|
||||
}
|
||||
} else if elem_sym.kind == .interface_ {
|
||||
elem_info := elem_sym.info as ast.Interface
|
||||
if elem_info.generic_types.len > 0 && elem_info.concrete_types.len == 0
|
||||
&& !node.elem_type.has_flag(.generic) {
|
||||
if c.table.cur_concrete_types.len == 0 {
|
||||
c.error('generic interface must specify type parameter, e.g. Foo<int>',
|
||||
node.elem_type_pos)
|
||||
} else {
|
||||
c.error('generic interface must specify type parameter, e.g. Foo<T>',
|
||||
node.elem_type_pos)
|
||||
}
|
||||
}
|
||||
} else if elem_sym.kind == .sum_type {
|
||||
elem_info := elem_sym.info as ast.SumType
|
||||
if elem_info.generic_types.len > 0 && elem_info.concrete_types.len == 0
|
||||
&& !node.elem_type.has_flag(.generic) {
|
||||
if c.table.cur_concrete_types.len == 0 {
|
||||
c.error('generic sumtype must specify type parameter, e.g. Foo<int>',
|
||||
node.elem_type_pos)
|
||||
} else {
|
||||
c.error('generic sumtype must specify type parameter, e.g. Foo<T>',
|
||||
node.elem_type_pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.exprs.len == 0 {
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/generic_interface_missing_type_names_err.vv:16:17: error: generic interface must specify type parameter, e.g. Foo<int>
|
||||
14 |
|
||||
15 | fn main() {
|
||||
16 | mut outs := []Output{}
|
||||
| ~~~~~~
|
||||
17 | outs << Coil { name: 'outhole' }
|
||||
18 | outs << Light { name: 'shoot again' }
|
@ -0,0 +1,19 @@
|
||||
interface Output<T> {
|
||||
val T
|
||||
name string
|
||||
}
|
||||
|
||||
struct Coil {
|
||||
pub mut: val int
|
||||
pub: name string [required]
|
||||
}
|
||||
struct Light {
|
||||
pub mut: val int
|
||||
pub: name string [required]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut outs := []Output{}
|
||||
outs << Coil { name: 'outhole' }
|
||||
outs << Light { name: 'shoot again' }
|
||||
}
|
Loading…
Reference in New Issue
Block a user