gen: add argument names to compile-time method struct (#9174)
parent
1b47e2953d
commit
a1e0f2bc46
|
@ -88,7 +88,8 @@ fn __print_assert_failure(i &VAssertMetaInfo) {
|
||||||
// MethodArgs holds type information for function and/or method arguments.
|
// MethodArgs holds type information for function and/or method arguments.
|
||||||
pub struct MethodArgs {
|
pub struct MethodArgs {
|
||||||
pub:
|
pub:
|
||||||
typ int
|
typ int
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
// FunctionData holds information about a parsed function.
|
// FunctionData holds information about a parsed function.
|
||||||
|
|
|
@ -336,7 +336,7 @@ fn (mut g Gen) comp_for(node ast.CompFor) {
|
||||||
// Skip receiver arg
|
// Skip receiver arg
|
||||||
for j, arg in method.params[1..] {
|
for j, arg in method.params[1..] {
|
||||||
typ := arg.typ.idx()
|
typ := arg.typ.idx()
|
||||||
g.write(typ.str())
|
g.write('{$typ.str(), _SLIT("$arg.name")}')
|
||||||
if j < len - 1 {
|
if j < len - 1 {
|
||||||
g.write(', ')
|
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