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:
parent
326e43385b
commit
93b7cc4888
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user