generics: fix generic_struct_insts_to_concrete (#9536)
							parent
							
								
									0b39de2fd3
								
							
						
					
					
						commit
						f1797a0150
					
				| 
						 | 
					@ -1093,27 +1093,22 @@ pub fn (mut t Table) generic_struct_insts_to_concrete() {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			mut parent_info := parent.info as Struct
 | 
								mut parent_info := parent.info as Struct
 | 
				
			||||||
			mut fields := parent_info.fields.clone()
 | 
								mut fields := parent_info.fields.clone()
 | 
				
			||||||
			for i, _ in fields {
 | 
								if parent_info.generic_types.len == info.generic_types.len {
 | 
				
			||||||
				mut field := fields[i]
 | 
									for i, _ in fields {
 | 
				
			||||||
				if field.typ.has_flag(.generic) {
 | 
										mut field := fields[i]
 | 
				
			||||||
					if parent_info.generic_types.len != info.generic_types.len {
 | 
										if t_typ := t.resolve_generic_by_types(field.typ, parent_info.generic_types,
 | 
				
			||||||
						// TODO: proper error
 | 
											info.generic_types)
 | 
				
			||||||
						panic('generic template mismatch')
 | 
										{
 | 
				
			||||||
					}
 | 
											field.typ = t_typ
 | 
				
			||||||
					for j, gp in parent_info.generic_types {
 | 
					 | 
				
			||||||
						if gp == field.typ {
 | 
					 | 
				
			||||||
							field.typ = info.generic_types[j].derive(field.typ).clear_flag(.generic)
 | 
					 | 
				
			||||||
							break
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
										fields[i] = field
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				fields[i] = field
 | 
									parent_info.generic_types = []
 | 
				
			||||||
 | 
									parent_info.fields = fields
 | 
				
			||||||
 | 
									typ.is_public = true
 | 
				
			||||||
 | 
									typ.kind = .struct_
 | 
				
			||||||
 | 
									typ.info = parent_info
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			parent_info.generic_types = []
 | 
					 | 
				
			||||||
			parent_info.fields = fields
 | 
					 | 
				
			||||||
			typ.is_public = true
 | 
					 | 
				
			||||||
			typ.kind = .struct_
 | 
					 | 
				
			||||||
			typ.info = parent_info
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,3 +49,15 @@ fn test_generics_with_generics_struct_string() {
 | 
				
			||||||
	assert ret.contains("data: ['foo', 'bar']")
 | 
						assert ret.contains("data: ['foo', 'bar']")
 | 
				
			||||||
	assert ret.contains('index: 11')
 | 
						assert ret.contains('index: 11')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn test_generics_struct_insts_to_concrete() {
 | 
				
			||||||
 | 
						ai := ArrayIterator<int>{
 | 
				
			||||||
 | 
							data: [11, 22],
 | 
				
			||||||
 | 
							index: 22
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						println(ai)
 | 
				
			||||||
 | 
						ret := '$ai'
 | 
				
			||||||
 | 
						assert ret.contains('ArrayIterator<int>{')
 | 
				
			||||||
 | 
						assert ret.contains('data: [11, 22]')
 | 
				
			||||||
 | 
						assert ret.contains('index: 22')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue