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

fmt: fix error of generic struct_init using module (fix #12893) (#12935)

This commit is contained in:
yuyi 2021-12-23 01:11:09 +08:00 committed by GitHub
parent 86719c5de9
commit 1028f0b59e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 8 deletions

View File

@ -24,7 +24,7 @@ pub interface JS.Response {
pub fn fetch(input string, init map[string]JS.Any) promise.Promise<JS.Response, JS.String> {
p_init := JS.Any(voidptr(0))
p := promise.Promise<JS.Response,String>{p_init}
p := promise.Promise<JS.Response, String>{p_init}
#let obj = {}; for (let [key,val] of init.map) { obj[key] = val; }
#p.promise = fetch(input.str,obj);

View File

@ -213,7 +213,7 @@ pub fn (mut f Fmt) short_module(name string) string {
generic_levels := name.trim_suffix('>').split('<')
mut res := '${f.short_module(generic_levels[0])}'
for i in 1 .. generic_levels.len {
genshorts := generic_levels[i].split(',').map(f.short_module(it)).join(',')
genshorts := generic_levels[i].split(', ').map(f.short_module(it)).join(', ')
res += '<$genshorts'
}
res += '>'

View File

@ -36,7 +36,7 @@ fn main() {
println(x.model)
println(x.permission)
//
mut a := Repo<User,Permission>{
mut a := Repo<User, Permission>{
model: User{
name: 'joe'
}

View File

@ -0,0 +1,8 @@
import v.fmt.tests.obj
struct GenericStruct<A, B> {
}
fn main() {
_ := GenericStruct<obj.Test, obj.Test>{}
}

View File

@ -0,0 +1,3 @@
module obj
pub struct Test {}

View File

@ -306,13 +306,13 @@ pub mut:
// return Repo<T,Permission>{db: db}
// }
fn test_generic_struct() {
mut a := Repo<User,Permission>{
mut a := Repo<User, Permission>{
model: User{
name: 'joe'
}
}
assert a.model.name == 'joe'
mut b := Repo<Group,Permission>{
mut b := Repo<Group, Permission>{
permission: Permission{
name: 'superuser'
}
@ -573,8 +573,8 @@ fn test_generic_detection() {
})
// this final case challenges your scanner :-)
assert boring_function<TandU<TandU<int, MultiLevel<Empty_>>, map[string][]int>>(TandU<TandU<int,MultiLevel<Empty_>>, map[string][]int>{
t: TandU<int,MultiLevel<Empty_>>{
assert boring_function<TandU<TandU<int, MultiLevel<Empty_>>, map[string][]int>>(TandU<TandU<int, MultiLevel<Empty_>>, map[string][]int>{
t: TandU<int, MultiLevel<Empty_>>{
t: 20
u: MultiLevel<Empty_>{
foo: Empty_{}

View File

@ -321,7 +321,7 @@ struct MultiGenericStruct<T, X> {
}
fn test_multi_generic_struct() {
x := MultiGenericStruct<TestStruct,TestStruct>{}
x := MultiGenericStruct<TestStruct, TestStruct>{}
assert '$x' == 'MultiGenericStruct<TestStruct, TestStruct>{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}'
assert x.str() == 'MultiGenericStruct<TestStruct, TestStruct>{\n t: TestStruct{\n x: 0\n }\n x: TestStruct{\n x: 0\n }\n}'
}