parent
							
								
									c0f4c525d2
								
							
						
					
					
						commit
						598d18cbd9
					
				| 
						 | 
					@ -440,3 +440,16 @@ fn test_map_clone() {
 | 
				
			||||||
	assert nums2['foo'] == 2
 | 
						assert nums2['foo'] == 2
 | 
				
			||||||
	assert nums2['bar'] == 8
 | 
						assert nums2['bar'] == 8
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct MValue {
 | 
				
			||||||
 | 
					    name string
 | 
				
			||||||
 | 
					    misc map[string]string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn test_map_default_zero() {
 | 
				
			||||||
 | 
					    m := map[string]MValue{}
 | 
				
			||||||
 | 
					    v := m['unknown']
 | 
				
			||||||
 | 
					    x := v.misc['x']
 | 
				
			||||||
 | 
					    println(x)
 | 
				
			||||||
 | 
						assert x == ''
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5414,7 +5414,24 @@ fn (mut g Gen) type_default(typ_ table.Type) string {
 | 
				
			||||||
	// User struct defined in another module.
 | 
						// User struct defined in another module.
 | 
				
			||||||
	// if typ.contains('__') {
 | 
						// if typ.contains('__') {
 | 
				
			||||||
	if sym.kind == .struct_ {
 | 
						if sym.kind == .struct_ {
 | 
				
			||||||
		return '{0}'
 | 
							mut has_array_map := false
 | 
				
			||||||
 | 
							mut zero_str := '{'
 | 
				
			||||||
 | 
							info := sym.info as table.Struct
 | 
				
			||||||
 | 
							for field in info.fields {
 | 
				
			||||||
 | 
								field_sym := g.table.get_type_symbol(field.typ)
 | 
				
			||||||
 | 
								if field_sym.kind in [.array, .map] {
 | 
				
			||||||
 | 
									zero_str += '.$field.name=${g.type_default(field.typ)},'
 | 
				
			||||||
 | 
									has_array_map = true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if has_array_map {
 | 
				
			||||||
 | 
								zero_str += '}'
 | 
				
			||||||
 | 
								type_name := g.typ(typ)
 | 
				
			||||||
 | 
								zero_str = '($type_name)' + zero_str
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								zero_str += '0}'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return zero_str
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// if typ.ends_with('Fn') { // TODO
 | 
						// if typ.ends_with('Fn') { // TODO
 | 
				
			||||||
	// return '0'
 | 
						// return '0'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue