parser: error if operators are used as function names (#7532)
parent
691e6f9d3f
commit
0caf668e73
|
@ -257,6 +257,10 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
}
|
}
|
||||||
if p.tok.kind in [.plus, .minus, .mul, .div, .mod] {
|
if p.tok.kind in [.plus, .minus, .mul, .div, .mod] {
|
||||||
name = p.tok.kind.str() // op_to_fn_name()
|
name = p.tok.kind.str() // op_to_fn_name()
|
||||||
|
if rec_type == table.void_type {
|
||||||
|
p.error_with_pos('cannot use operator overloading with normal functions',
|
||||||
|
p.tok.position())
|
||||||
|
}
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
// <T>
|
// <T>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/parser/tests/operator_normal_fn.vv:1:4: error: cannot use operator overloading with normal functions
|
||||||
|
1 | fn +(x int) int {
|
||||||
|
| ^
|
||||||
|
2 | return 5 + x
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn +(x int) int {
|
||||||
|
return 5 + x
|
||||||
|
}
|
Loading…
Reference in New Issue