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

cgen: allow using of original operation if alias is number and no custom method is defined (#17718)

This commit is contained in:
Swastik Baranwal 2023-03-21 15:09:58 +05:30 committed by GitHub
parent 326e43385b
commit 93b7cc4888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -286,3 +286,9 @@ fn test_add_seconds_to_time() {
future_tm := now_tm.add_seconds(60)
assert now_tm.unix < future_tm.unix
}
fn test_plus_equals_duration() {
mut d := time.second
d += time.second
assert d == 2 * time.second
}

View File

@ -454,6 +454,15 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.expr(val)
g.writeln(');')
return
} else if left_sym.kind == .alias
&& g.table.final_sym(g.unwrap_generic(var_type)).is_number()
&& !left_sym.has_method(extracted_op) {
g.write(' = ')
g.expr(left)
g.write(' ${extracted_op} ')
g.expr(val)
g.write(';')
return
} else {
g.write(' = ${styp}_${util.replace_op(extracted_op)}(')
method := g.table.find_method(left_sym, extracted_op) or {