fix pushing to mutable array args
							parent
							
								
									918edad525
								
							
						
					
					
						commit
						83022a2478
					
				|  | @ -948,9 +948,10 @@ fn (p mut Parser) fn_call_args(f mut Fn) &Fn { | |||
| 			// Reference
 | ||||
| 			// TODO ptr hacks. DOOM hacks, fix please.
 | ||||
| 			if !got_ptr && exp_ptr && got != 'voidptr' { | ||||
| 				// Special case for mutable arrays. We can't `&` function results,
 | ||||
| 				// Special case for mutable arrays. We can't `&` function
 | ||||
| 				// results,
 | ||||
| 				// have to use `(array[]){ expr }` hack.
 | ||||
| 				if expected.starts_with('array_') && exp_ptr { | ||||
| 				if expected.starts_with('array_') && exp_ptr { //&& !arg.is_mut{
 | ||||
| 					p.cgen.set_placeholder(ph, '& /*111*/ (array[]){') | ||||
| 					p.gen('}[0] ') | ||||
| 				} | ||||
|  |  | |||
|  | @ -2350,6 +2350,10 @@ fn (p mut Parser) expression() string { | |||
| 			if !p.expr_var.is_mut && !p.pref.translated { | ||||
| 				p.error('`$p.expr_var.name` is immutable (can\'t <<)') | ||||
| 			} | ||||
| 			if p.expr_var.is_arg && p.expr_var.typ.starts_with('array_') { | ||||
| 				p.error("for now it's not possible to append an element to "+ | ||||
| 					'a mutable array argument `$p.expr_var.name`') | ||||
| 			}	 | ||||
| 			if !p.expr_var.is_changed { | ||||
| 				p.mark_var_changed(p.expr_var) | ||||
| 			} | ||||
|  |  | |||
|  | @ -69,7 +69,7 @@ fn modify_array(a mut []int) { | |||
| 	for i in 0..a.len { | ||||
| 		a[i] = a[i] * 2 | ||||
| 	} | ||||
| 	a << 888  | ||||
| 	//a << 888
 | ||||
| } | ||||
| 
 | ||||
| fn test_mut_array() { | ||||
|  |  | |||
|  | @ -10,21 +10,21 @@ pub mut: | |||
| 
 | ||||
| fn foo(b int, a mut []int) { | ||||
| 	a[0] = 7 | ||||
| 	a << 4  | ||||
| 	//a << 4
 | ||||
| } | ||||
| 
 | ||||
| // TODO 
 | ||||
| fn test_mut() { | ||||
| 	mut numbers := [1,2,3] | ||||
| 	foo(7, mut numbers) | ||||
| 	//assert a.len == 4 
 | ||||
| 	assert numbers[0] == 7  | ||||
| 	//assert a[3] == 4 
 | ||||
| 
 | ||||
| 	assert numbers.len == 3 | ||||
| 	// TODO bring back once << works with mutable args
 | ||||
| 	//assert numbers.len == 4
 | ||||
| 	//assert numbers[0] == 7
 | ||||
| 	//assert numbers[3] == 4
 | ||||
| 	println(numbers) | ||||
| 	n := 1 | ||||
| 	mut b := &n | ||||
| 	*b = 10 | ||||
| 
 | ||||
| 	//mut b := mut a
 | ||||
| 	//b = 10
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue