File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1552,6 +1552,15 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
1552
1552
c.table.register_fn_concrete_types (method.fkey (), concrete_types)
1553
1553
}
1554
1554
1555
+ // resolve return generics struct to concrete type
1556
+ if method.generic_names.len > 0 && method.return_type.has_flag (.generic)
1557
+ && ! isnil (c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 {
1558
+ node.return_type = c.table.unwrap_generic_type (method.return_type, method.generic_names,
1559
+ concrete_types)
1560
+ } else {
1561
+ node.return_type = method.return_type
1562
+ }
1563
+
1555
1564
if node.concrete_types.len > 0 && node.concrete_types.all (! it .has_flag (.generic))
1556
1565
&& method.return_type.has_flag (.generic) && method.generic_names.len > 0
1557
1566
&& method.generic_names.len == node.concrete_types.len {
Original file line number Diff line number Diff line change
1
+ import json
2
+
3
+ pub struct NotificationMessage < T> {
4
+ pub :
5
+ method string
6
+ params T
7
+ }
8
+
9
+ struct Abc {}
10
+
11
+ pub fn (x &Abc) notification_at <T >() ? NotificationMessage< T> {
12
+ return json.decode (NotificationMessage< T> , '{}' )
13
+ }
14
+
15
+ pub fn (x &Abc) generic_method <T >(method_name string ) ? NotificationMessage< T> {
16
+ return x.notification_at <T >()
17
+ }
18
+
19
+ struct Res {}
20
+
21
+ pub fn (mut x Abc) diagnostics () ? Res {
22
+ got := x.generic_method <Res >('xyz' )?
23
+ return got.params
24
+ }
25
+
26
+ fn test_generic_method_returning_optional () ? {
27
+ mut a := Abc{}
28
+ a.diagnostics ()?
29
+ assert true
30
+ }
You can’t perform that action at this time.
0 commit comments