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

cgen: fix vweb using generic method (fix #15888) (#15963)

This commit is contained in:
yuyi
2022-10-05 18:23:47 +08:00
committed by GitHub
parent 46138a2841
commit 6ccdf89546
2 changed files with 40 additions and 5 deletions

View File

@ -64,3 +64,31 @@ fn (mut app App) time_json_pretty() {
'time': time.now().format()
})
}
struct ApiSuccessResponse<T> {
success bool
result T
}
fn (mut app App) json_success<T>(result T) vweb.Result {
response := ApiSuccessResponse<T>{
success: true
result: result
}
return app.json(response)
}
// should compile, this is a helper method, not exposed as a route
fn (mut app App) some_helper<T>(result T) ApiSuccessResponse<T> {
response := ApiSuccessResponse<T>{
success: true
result: result
}
return response
}
// should compile, the route method itself is not generic
fn (mut app App) ok() vweb.Result {
return app.json(app.some_helper(123))
}