cgen: fix assigning a new value to the mut sumtype receiver (#13204)
							parent
							
								
									91bfab79a5
								
							
						
					
					
						commit
						ef562c92a5
					
				| 
						 | 
				
			
			@ -435,7 +435,12 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) {
 | 
			
		|||
						if op_overloaded {
 | 
			
		||||
							g.op_arg(val, op_expected_right, val_type)
 | 
			
		||||
						} else {
 | 
			
		||||
							g.expr_with_cast(val, val_type, var_type)
 | 
			
		||||
							exp_type := if left.is_auto_deref_var() {
 | 
			
		||||
								var_type.deref()
 | 
			
		||||
							} else {
 | 
			
		||||
								var_type
 | 
			
		||||
							}
 | 
			
		||||
							g.expr_with_cast(val, val_type, exp_type)
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
pub type Foo = Bar | Baz
 | 
			
		||||
 | 
			
		||||
fn (mut f Foo) set_baz() {
 | 
			
		||||
	f = Baz{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct Bar {}
 | 
			
		||||
 | 
			
		||||
pub struct Baz {}
 | 
			
		||||
 | 
			
		||||
fn test_mut_receiver_of_sumtype() {
 | 
			
		||||
	mut x := Foo(Bar{})
 | 
			
		||||
	x.set_baz()
 | 
			
		||||
 | 
			
		||||
	println(x)
 | 
			
		||||
	assert '$x' == 'Foo(Baz{})'
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue