cgen: fix comptime call argument auto conversion for indexexpr (fix #15232) (#21796)

This commit is contained in:
Felipe Pena 2024-07-03 13:26:03 -03:00 committed by GitHub
parent 30b3ab6f41
commit 9b6578e883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -154,7 +154,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
arg := node.args.last()
param := m.params[node.args.len]
arg.expr is ast.Ident && g.table.type_to_str(arg.typ) == '[]string'
arg.expr in [ast.IndexExpr, ast.Ident] && g.table.type_to_str(arg.typ) == '[]string'
&& g.table.type_to_str(param.typ) != '[]string'
} else {
false

View file

@ -0,0 +1,17 @@
struct Dummy {}
fn (d Dummy) sample(x int) int {
return x + 1
}
fn test_main() {
args := ['0', '5']
$for method in Dummy.methods {
if args.len > 1 {
assert Dummy{}.$method(args[1 ..]) == 6
tmp := args[1..]
assert Dummy{}.$method(tmp) == 6
}
}
}