File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,14 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
86
86
if ! field.typ.has_flag (.shared_f) {
87
87
g.is_shared = false
88
88
}
89
- inited_fields[field.name] = i
89
+ mut field_name := field.name
90
+ if node.no_keys && sym.kind == .struct_ {
91
+ info := sym.info as ast.Struct
92
+ if info.fields.len == node.fields.len {
93
+ field_name = info.fields[i].name
94
+ }
95
+ }
96
+ inited_fields[field_name] = i
90
97
if sym.kind != .struct_ {
91
98
if field.typ == 0 {
92
99
g.checker_bug ('struct init, field.typ is 0' , field.pos)
@@ -205,6 +212,12 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
205
212
sfield.expected_type = tt
206
213
}
207
214
}
215
+ if node.no_keys && sym.kind == .struct_ {
216
+ sym_info := sym.info as ast.Struct
217
+ if sym_info.fields.len == node.fields.len {
218
+ sfield.name = sym_info.fields[already_initalised_node_field_index].name
219
+ }
220
+ }
208
221
g.struct_init_field (sfield, sym.language)
209
222
if is_multiline {
210
223
g.writeln (',' )
Original file line number Diff line number Diff line change
1
+ struct Am {
2
+ inner int
3
+ }
4
+
5
+ fn convert [T](num int ) T {
6
+ return T{num}
7
+ }
8
+
9
+ fn test_generic_struct_no_key_init () {
10
+ println (convert[Am](3 ).inner)
11
+ assert convert[Am](3 ).inner == 3
12
+ }
You can’t perform that action at this time.
0 commit comments