mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
be0dc0e537
commit
550b27b014
@ -519,6 +519,16 @@ pub 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') {
|
||||
c.error('sum type `$node.name` cannot be defined recursively', variant.pos)
|
||||
}
|
||||
for param in 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sym.name.trim_string_left(sym.mod + '.') == node.name {
|
||||
|
5
vlib/v/checker/tests/sumtype_define_recursively.out
Normal file
5
vlib/v/checker/tests/sumtype_define_recursively.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/sumtype_define_recursively.vv:1:13: error: sum type `Expr` cannot be defined recursively
|
||||
1 | type Expr = fn ([]Expr) Expr | int
|
||||
| ~~~~~~~~~~~~~~~~
|
||||
2 |
|
||||
3 | fn f(exprs []Expr) Expr {
|
10
vlib/v/checker/tests/sumtype_define_recursively.vv
Normal file
10
vlib/v/checker/tests/sumtype_define_recursively.vv
Normal file
@ -0,0 +1,10 @@
|
||||
type Expr = fn ([]Expr) Expr | int
|
||||
|
||||
fn f(exprs []Expr) Expr {
|
||||
return 0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut m := map[string]Expr{}
|
||||
m['f'] = f
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user