mirror of
https://github.com/vlang/v.git
synced 2025-09-12 08:57:09 -04:00
parent
f3baaa0fb8
commit
d0de08338f
@ -139,7 +139,8 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sym := g.table.sym(g.unwrap_generic(node.left_type))
|
left_type := g.unwrap_generic(node.left_type)
|
||||||
|
sym := g.table.sym(left_type)
|
||||||
g.trace_autofree('// \$method call. sym="${sym.name}"')
|
g.trace_autofree('// \$method call. sym="${sym.name}"')
|
||||||
if node.method_name == 'method' {
|
if node.method_name == 'method' {
|
||||||
// `app.$method()`
|
// `app.$method()`
|
||||||
@ -187,7 +188,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: check argument types
|
// TODO: check argument types
|
||||||
g.write('${util.no_dots(sym.name)}_${g.comptime.comptime_for_method.name}(')
|
g.write('${g.cc_type(left_type, false)}_${g.comptime.comptime_for_method.name}(')
|
||||||
|
|
||||||
// try to see if we need to pass a pointer
|
// try to see if we need to pass a pointer
|
||||||
if mut node.left is ast.Ident {
|
if mut node.left is ast.Ident {
|
||||||
@ -279,7 +280,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
|||||||
}
|
}
|
||||||
g.write('if (string__eq(${node.method_name}, _SLIT("${method.name}"))) ')
|
g.write('if (string__eq(${node.method_name}, _SLIT("${method.name}"))) ')
|
||||||
}
|
}
|
||||||
g.write('${util.no_dots(sym.name)}_${method.name}(${amp} ')
|
g.write('${g.cc_type(left_type, false)}_${method.name}(${amp} ')
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
g.writeln(');')
|
g.writeln(');')
|
||||||
j++
|
j++
|
||||||
|
26
vlib/v/tests/comptime/comptime_call_map_receiver_test.v
Normal file
26
vlib/v/tests/comptime/comptime_call_map_receiver_test.v
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
type Any = string | int
|
||||||
|
|
||||||
|
fn (m map[string]Any) to_toml() string {
|
||||||
|
mut t := ''
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
mut doc := map[string]Any{}
|
||||||
|
_ := encode(doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode[T](typ T) string {
|
||||||
|
$for method in T.methods {
|
||||||
|
$if method.name == 'to_toml' {
|
||||||
|
return typ.$method()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp := encode_struct[T](typ)
|
||||||
|
return mp.to_toml()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode_struct[T](typ T) map[string]Any {
|
||||||
|
mut mp := map[string]Any{}
|
||||||
|
return mp
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user