gen: add argument names to compile-time method struct (#9174)

pull/9188/head
Miccah 2021-03-07 07:28:43 -06:00 committed by GitHub
parent 1b47e2953d
commit a1e0f2bc46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -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.

View File

@ -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(', ')
}

View File

@ -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'
}
}
}