1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: clean up sum_type_decl() (#17669)

This commit is contained in:
yuyi 2023-03-15 22:56:41 +08:00 committed by GitHub
parent 2e7dd8543a
commit aa50f4ebf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -548,7 +548,7 @@ fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
c.error('sum type cannot hold a reference type', variant.pos)
}
c.ensure_type_exists(variant.typ, variant.pos) or {}
mut sym := c.table.sym(variant.typ)
sym := c.table.sym(variant.typ)
if sym.name in names_used {
c.error('sum type ${node.name} cannot hold the type `${sym.name}` more than once',
variant.pos)
@ -558,7 +558,7 @@ 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 a JS struct', variant.pos)
} else if mut sym.info is ast.Struct {
} else if sym.info is ast.Struct {
if sym.info.is_generic {
if !variant.typ.has_flag(.generic) {
c.error('generic struct `${sym.name}` must specify generic type names, e.g. ${sym.name}[T]',
@ -581,11 +581,10 @@ fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
}
}
} else if sym.info is ast.FnType {
func := (sym.info as ast.FnType).func
if c.table.sym(func.return_type).name.ends_with('.${node.name}') {
if c.table.sym(sym.info.func.return_type).name.ends_with('.${node.name}') {
c.error('sum type `${node.name}` cannot be defined recursively', variant.pos)
}
for param in func.params {
for param in sym.info.func.params {
if c.table.sym(param.typ).name.ends_with('.${node.name}') {
c.error('sum type `${node.name}` cannot be defined recursively', variant.pos)
}