checker: fix array append short struct init (#8362)
							parent
							
								
									2b30c48770
								
							
						
					
					
						commit
						d1ab22d45f
					
				|  | @ -476,7 +476,12 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type { | |||
| 			c.error('unexpected short struct syntax', struct_init.pos) | ||||
| 			return table.void_type | ||||
| 		} | ||||
| 		struct_init.typ = c.expected_type | ||||
| 		sym := c.table.get_type_symbol(c.expected_type) | ||||
| 		if sym.kind == .array { | ||||
| 			struct_init.typ = c.table.value_type(c.expected_type) | ||||
| 		} else { | ||||
| 			struct_init.typ = c.expected_type | ||||
| 		} | ||||
| 	} | ||||
| 	if struct_init.typ == 0 { | ||||
| 		c.error('unknown type', struct_init.pos) | ||||
|  |  | |||
|  | @ -0,0 +1,12 @@ | |||
| struct Page { | ||||
|     contents int | ||||
| } | ||||
| 
 | ||||
| fn test_array_append_short_struct() { | ||||
| 	mut pages := []Page{} | ||||
| 	pages << { | ||||
| 		contents: 3 | ||||
| 	} | ||||
| 	println(pages) | ||||
| 	assert pages == [Page{ contents: 3}] | ||||
| } | ||||
		Loading…
	
		Reference in New Issue