mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check generic sumtype declare error (#14367)
This commit is contained in:
parent
34a252ef84
commit
cd4fa041ff
@ -492,7 +492,13 @@ pub fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
|
||||
c.error('sum type cannot hold an interface', variant.pos)
|
||||
} else if sym.kind == .struct_ && sym.language == .js {
|
||||
c.error('sum type cannot hold an JS struct', variant.pos)
|
||||
} else if mut sym.info is ast.Struct {
|
||||
if sym.info.is_generic && !variant.typ.has_flag(.generic) {
|
||||
c.error('generic struct `$sym.name` must specify generic type names, e.g. Foo<T>',
|
||||
variant.pos)
|
||||
}
|
||||
}
|
||||
|
||||
if sym.name.trim_string_left(sym.mod + '.') == node.name {
|
||||
c.error('sum type cannot hold itself', variant.pos)
|
||||
}
|
||||
|
7
vlib/v/checker/tests/generic_sumtype_decl_err.out
Normal file
7
vlib/v/checker/tests/generic_sumtype_decl_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/generic_sumtype_decl_err.vv:7:24: error: generic struct `Just` must specify generic type names, e.g. Foo<T>
|
||||
5 | struct Nothing {}
|
||||
6 |
|
||||
7 | type Maybe = Nothing | Just
|
||||
| ~~~~
|
||||
8 |
|
||||
9 | fn main() {
|
10
vlib/v/checker/tests/generic_sumtype_decl_err.vv
Normal file
10
vlib/v/checker/tests/generic_sumtype_decl_err.vv
Normal file
@ -0,0 +1,10 @@
|
||||
struct Just<T> {
|
||||
value T
|
||||
}
|
||||
|
||||
struct Nothing {}
|
||||
|
||||
type Maybe = Nothing | Just
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue
Block a user