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

all: only allow defining == and < and auto generate !=, >, >= and <= (#8520)

This commit is contained in:
Swastik Baranwal
2021-02-03 19:48:38 +05:30
committed by GitHub
parent 9dcf673216
commit 7ec116d588
14 changed files with 88 additions and 152 deletions

View File

@@ -3637,7 +3637,8 @@ To improve safety and maintainability, operator overloading is limited:
- `==` and `!=` are self generated by the compiler but can be overriden.
- Calling other functions inside operator functions is not allowed.
- Operator functions can't modify their arguments.
- When using `<`, `>`, `>=`, `<=`, `==` and `!=` operators, the return type must be `bool`.
- When using `<` and `==` operators, the return type must be `bool`.
- `!=`, `>`, `<=` and `>=` are auto generated when `==` and `<` are defined.
- Both arguments must have the same type (just like with all operators in V).
- Assignment operators (`*=`, `+=`, `/=`, etc)
are auto generated when the operators are defined though they must return the same type.