mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: error if operators are used as function names (#7532)
This commit is contained in:
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] {
|
||||
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()
|
||||
}
|
||||
// <T>
|
||||
|
5
vlib/v/parser/tests/operator_normal_fn.out
Normal file
5
vlib/v/parser/tests/operator_normal_fn.out
Normal file
@ -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 | }
|
3
vlib/v/parser/tests/operator_normal_fn.vv
Normal file
3
vlib/v/parser/tests/operator_normal_fn.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn +(x int) int {
|
||||
return 5 + x
|
||||
}
|
Loading…
Reference in New Issue
Block a user