Skip to content

Commit d0de083

Browse files
authored
cgen: fix comptimecall with map receiver (fix #24448) (#24449)
1 parent f3baaa0 commit d0de083

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎vlib/v/gen/c/comptime.v‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
139139
}
140140
return
141141
}
142-
sym := g.table.sym(g.unwrap_generic(node.left_type))
142+
left_type := g.unwrap_generic(node.left_type)
143+
sym := g.table.sym(left_type)
143144
g.trace_autofree('// \$method call. sym="${sym.name}"')
144145
if node.method_name == 'method' {
145146
// `app.$method()`
@@ -187,7 +188,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
187188
}
188189
}
189190
// TODO: check argument types
190-
g.write('${util.no_dots(sym.name)}_${g.comptime.comptime_for_method.name}(')
191+
g.write('${g.cc_type(left_type, false)}_${g.comptime.comptime_for_method.name}(')
191192

192193
// try to see if we need to pass a pointer
193194
if mut node.left is ast.Ident {
@@ -279,7 +280,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
279280
}
280281
g.write('if (string__eq(${node.method_name}, _SLIT("${method.name}"))) ')
281282
}
282-
g.write('${util.no_dots(sym.name)}_${method.name}(${amp} ')
283+
g.write('${g.cc_type(left_type, false)}_${method.name}(${amp} ')
283284
g.expr(node.left)
284285
g.writeln(');')
285286
j++
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type Any = string | int
2+
3+
fn (m map[string]Any) to_toml() string {
4+
mut t := ''
5+
return t
6+
}
7+
8+
fn test_main() {
9+
mut doc := map[string]Any{}
10+
_ := encode(doc)
11+
}
12+
13+
fn encode[T](typ T) string {
14+
$for method in T.methods {
15+
$if method.name == 'to_toml' {
16+
return typ.$method()
17+
}
18+
}
19+
mp := encode_struct[T](typ)
20+
return mp.to_toml()
21+
}
22+
23+
fn encode_struct[T](typ T) map[string]Any {
24+
mut mp := map[string]Any{}
25+
return mp
26+
}

0 commit comments

Comments
 (0)