1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix interface method with fntype argument (#15280)

This commit is contained in:
yuyi 2022-07-30 19:29:41 +08:00 committed by GitHub
parent e6a04905e9
commit 6e8350a9c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -1736,6 +1736,18 @@ pub fn (s string) all_after_last(sub string) string {
return s[pos + sub.len..]
}
// all_after_first returns the contents after the first occurence of `sub` in the string.
// If the substring is not found, it returns the full input string.
// Example: assert '23:34:45.234'.all_after_first(':') == '34:45.234'
// Example: assert 'abcd'.all_after_first('z') == 'abcd'
pub fn (s string) all_after_first(sub string) string {
pos := s.index_(sub)
if pos == -1 {
return s.clone()
}
return s[pos + sub.len..]
}
// after returns the contents after the last occurence of `sub` in the string.
// If the substring is not found, it returns the full input string.
// Example: assert '23:34:45.234'.after(':') == '45.234'

View File

@ -1202,7 +1202,7 @@ pub fn (mut f Fmt) interface_field(field ast.StructField) {
pub fn (mut f Fmt) interface_method(method ast.FnDecl) {
f.write('\t')
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).all_after_first('fn '))
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
f.writeln('')
f.comments(method.next_comments, inline: false, has_nl: true, level: .indent)

View File

@ -0,0 +1,23 @@
module main
interface Test {
test(fn (Test))
}
struct Test1 {
}
fn (t Test1) test(f fn (Test)) {
f(Test(t))
}
fn main() {
t := Test1{}
t.test(fn [t] (t1 Test) {
println('$t, $t1')
t.test(fn [t] (t2 Test) {
println('$t, $t2')
})
})
}