gen: add argument names to compile-time method struct (#9174)
parent
1b47e2953d
commit
a1e0f2bc46
|
@ -89,6 +89,7 @@ fn __print_assert_failure(i &VAssertMetaInfo) {
|
|||
pub struct MethodArgs {
|
||||
pub:
|
||||
typ int
|
||||
name string
|
||||
}
|
||||
|
||||
// FunctionData holds information about a parsed function.
|
||||
|
|
|
@ -336,7 +336,7 @@ fn (mut g Gen) comp_for(node ast.CompFor) {
|
|||
// Skip receiver arg
|
||||
for j, arg in method.params[1..] {
|
||||
typ := arg.typ.idx()
|
||||
g.write(typ.str())
|
||||
g.write('{$typ.str(), _SLIT("$arg.name")}')
|
||||
if j < len - 1 {
|
||||
g.write(', ')
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
struct TestStruct {}
|
||||
|
||||
fn (t TestStruct) test(arg1 string, arg2 string, arg3 string) {}
|
||||
|
||||
fn test_comptime_method_names() {
|
||||
$for method in TestStruct.methods {
|
||||
if method.name == 'test' {
|
||||
args := method.args
|
||||
assert args[0].name == 'arg1'
|
||||
assert args[1].name == 'arg2'
|
||||
assert args[2].name == 'arg3'
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue