mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
398bd2280d
commit
032cb3f115
@ -598,6 +598,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||||||
c.error('unwrapped optional cannot be used in an infix expression', opt_infix_pos)
|
c.error('unwrapped optional cannot be used in an infix expression', opt_infix_pos)
|
||||||
}
|
}
|
||||||
// Dual sides check (compatibility check)
|
// Dual sides check (compatibility check)
|
||||||
|
if node.left !is ast.ComptimeCall && node.right !is ast.ComptimeCall {
|
||||||
if !(c.symmetric_check(left_type, right_type) && c.symmetric_check(right_type, left_type))
|
if !(c.symmetric_check(left_type, right_type) && c.symmetric_check(right_type, left_type))
|
||||||
&& !c.pref.translated && !c.file.is_translated && !node.left.is_auto_deref_var()
|
&& !c.pref.translated && !c.file.is_translated && !node.left.is_auto_deref_var()
|
||||||
&& !node.right.is_auto_deref_var() {
|
&& !node.right.is_auto_deref_var() {
|
||||||
@ -620,6 +621,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
|||||||
left_right_pos)
|
left_right_pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
if (node.left is ast.InfixExpr &&
|
if (node.left is ast.InfixExpr &&
|
||||||
(node.left as ast.InfixExpr).op == .inc) ||
|
(node.left as ast.InfixExpr).op == .inc) ||
|
||||||
|
@ -104,7 +104,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
|
|||||||
c.error('cannot use `${c.table.type_to_str(got_typ)}` as type `${c.table.type_to_str(exp_type)}` in return argument',
|
c.error('cannot use `${c.table.type_to_str(got_typ)}` as type `${c.table.type_to_str(exp_type)}` in return argument',
|
||||||
pos)
|
pos)
|
||||||
}
|
}
|
||||||
if !c.check_types(got_typ, exp_type) {
|
if node.exprs[expr_idxs[i]] !is ast.ComptimeCall && !c.check_types(got_typ, exp_type) {
|
||||||
got_typ_sym := c.table.sym(got_typ)
|
got_typ_sym := c.table.sym(got_typ)
|
||||||
mut exp_typ_sym := c.table.sym(exp_type)
|
mut exp_typ_sym := c.table.sym(exp_type)
|
||||||
if exp_typ_sym.kind == .interface_ {
|
if exp_typ_sym.kind == .interface_ {
|
||||||
|
24
vlib/v/tests/comptime_call_type_test.v
Normal file
24
vlib/v/tests/comptime_call_type_test.v
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
struct App {}
|
||||||
|
|
||||||
|
fn (mut app App) method_one() int {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut app App) method_two() int {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reflect_call(method_name string) int {
|
||||||
|
a := App{}
|
||||||
|
$for method in App.methods {
|
||||||
|
if method.name == method_name {
|
||||||
|
return a.$method()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic('Method not supported: $method_name')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_comptime_call_type() {
|
||||||
|
result := reflect_call('method_one')
|
||||||
|
assert result == 1
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user