cgen: print bool and string correctly in struct
							parent
							
								
									50d5e23694
								
							
						
					
					
						commit
						4aedef367c
					
				| 
						 | 
					@ -17,5 +17,8 @@ indent_size = 2
 | 
				
			||||||
[*.md]
 | 
					[*.md]
 | 
				
			||||||
trim_trailing_whitespace = false
 | 
					trim_trailing_whitespace = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[*.txt]
 | 
				
			||||||
 | 
					insert_final_newline = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[Makefile]
 | 
					[Makefile]
 | 
				
			||||||
indent_style = tab
 | 
					indent_style = tab
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2952,6 +2952,8 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) {
 | 
				
			||||||
		g.definitions.write('a.' + field.name)
 | 
							g.definitions.write('a.' + field.name)
 | 
				
			||||||
		if field.typ == table.string_type {
 | 
							if field.typ == table.string_type {
 | 
				
			||||||
			g.definitions.write('.len, a.${field.name}.str')
 | 
								g.definitions.write('.len, a.${field.name}.str')
 | 
				
			||||||
 | 
							} else if field.typ == table.bool_type {
 | 
				
			||||||
 | 
								g.definitions.write(' == true ? 4 : 5, a.${field.name} == true ? "true" : "false"')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if i < info.fields.len - 1 {
 | 
							if i < info.fields.len - 1 {
 | 
				
			||||||
			g.definitions.write(', ')
 | 
								g.definitions.write(', ')
 | 
				
			||||||
| 
						 | 
					@ -2963,6 +2965,8 @@ fn (g mut Gen) gen_str_for_type(sym table.TypeSymbol, styp string) {
 | 
				
			||||||
fn type_to_fmt(typ table.Type) string {
 | 
					fn type_to_fmt(typ table.Type) string {
 | 
				
			||||||
	n := int(typ)
 | 
						n := int(typ)
 | 
				
			||||||
	if n == table.string_type {
 | 
						if n == table.string_type {
 | 
				
			||||||
 | 
							return '\'%.*s\''
 | 
				
			||||||
 | 
						} else if n == table.bool_type {
 | 
				
			||||||
		return '%.*s'
 | 
							return '%.*s'
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return '%d'
 | 
						return '%d'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
MyStruct {
 | 
					MyStruct {
 | 
				
			||||||
	s: 6
 | 
						s: '6'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue