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:
parent
2e7dd8543a
commit
aa50f4ebf7
@ -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.error('sum type cannot hold a reference type', variant.pos)
|
||||||
}
|
}
|
||||||
c.ensure_type_exists(variant.typ, variant.pos) or {}
|
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 {
|
if sym.name in names_used {
|
||||||
c.error('sum type ${node.name} cannot hold the type `${sym.name}` more than once',
|
c.error('sum type ${node.name} cannot hold the type `${sym.name}` more than once',
|
||||||
variant.pos)
|
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)
|
c.error('sum type cannot hold an interface', variant.pos)
|
||||||
} else if sym.kind == .struct_ && sym.language == .js {
|
} else if sym.kind == .struct_ && sym.language == .js {
|
||||||
c.error('sum type cannot hold a JS struct', variant.pos)
|
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 sym.info.is_generic {
|
||||||
if !variant.typ.has_flag(.generic) {
|
if !variant.typ.has_flag(.generic) {
|
||||||
c.error('generic struct `${sym.name}` must specify generic type names, e.g. ${sym.name}[T]',
|
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 {
|
} else if sym.info is ast.FnType {
|
||||||
func := (sym.info as ast.FnType).func
|
if c.table.sym(sym.info.func.return_type).name.ends_with('.${node.name}') {
|
||||||
if c.table.sym(func.return_type).name.ends_with('.${node.name}') {
|
|
||||||
c.error('sum type `${node.name}` cannot be defined recursively', variant.pos)
|
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}') {
|
if c.table.sym(param.typ).name.ends_with('.${node.name}') {
|
||||||
c.error('sum type `${node.name}` cannot be defined recursively', variant.pos)
|
c.error('sum type `${node.name}` cannot be defined recursively', variant.pos)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user