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

checker: fix vls test compilation

This commit is contained in:
Delyan Angelov 2022-08-22 08:22:46 +03:00
parent 0d9ac1f59c
commit 24e0a6cff2
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 39 additions and 0 deletions

View File

@ -1552,6 +1552,15 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
c.table.register_fn_concrete_types(method.fkey(), concrete_types)
}
// resolve return generics struct to concrete type
if method.generic_names.len > 0 && method.return_type.has_flag(.generic)
&& !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 {
node.return_type = c.table.unwrap_generic_type(method.return_type, method.generic_names,
concrete_types)
} else {
node.return_type = method.return_type
}
if node.concrete_types.len > 0 && node.concrete_types.all(!it.has_flag(.generic))
&& method.return_type.has_flag(.generic) && method.generic_names.len > 0
&& method.generic_names.len == node.concrete_types.len {

View File

@ -0,0 +1,30 @@
import json
pub struct NotificationMessage<T> {
pub:
method string
params T
}
struct Abc {}
pub fn (x &Abc) notification_at<T>() ?NotificationMessage<T> {
return json.decode(NotificationMessage<T>, '{}')
}
pub fn (x &Abc) generic_method<T>(method_name string) ?NotificationMessage<T> {
return x.notification_at<T>()
}
struct Res {}
pub fn (mut x Abc) diagnostics() ?Res {
got := x.generic_method<Res>('xyz')?
return got.params
}
fn test_generic_method_returning_optional() ? {
mut a := Abc{}
a.diagnostics()?
assert true
}