checker: check generic sumtype declare error (#14367)
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)
|
||||
}
|
||||
|
|
|
@ -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() {
|
|
@ -0,0 +1,10 @@
|
|||
struct Just<T> {
|
||||
value T
|
||||
}
|
||||
|
||||
struct Nothing {}
|
||||
|
||||
type Maybe = Nothing | Just
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue