parser: a small immutable field fix
							parent
							
								
									343dced36d
								
							
						
					
					
						commit
						ae2af4c36d
					
				|  | @ -2179,9 +2179,8 @@ fn (p mut Parser) dot(str_typ_ string, method_ph int) string { | |||
| 		next := p.peek() | ||||
| 		modifying := next.is_assign() || next == .inc || next == .dec || | ||||
| 			(field.typ.starts_with('array_') && next == .left_shift) | ||||
| 		is_vi := p.fileis('vid') | ||||
| 		if !p.builtin_mod && !p.pref.translated && modifying && !is_vi | ||||
| 			&& p.has_immutable_field { | ||||
| 		if !p.builtin_mod && !p.pref.translated && modifying && | ||||
| 			p.has_immutable_field { | ||||
| 			f := p.first_immutable_field | ||||
| 			p.error_with_token_index('cannot modify immutable field `$f.name` (type `$f.parent_fn`)\n' + | ||||
| 					'declare the field with `mut:` | ||||
|  | @ -2190,8 +2189,6 @@ struct $f.parent_fn { | |||
| 	$f.name $f.typ | ||||
| } | ||||
| ', fname_tidx) | ||||
| 		} | ||||
| 		if !p.builtin_mod && p.mod != typ.mod { | ||||
| 		} | ||||
| 		// Don't allow `arr.data`
 | ||||
| 		if field.access_mod == .private && !p.builtin_mod && !p.pref.translated && p.mod != typ.mod { | ||||
|  |  | |||
|  | @ -107,3 +107,14 @@ fn test_reserved_keywords() { | |||
| 	assert rk_holder2.volatile == 11 | ||||
| 	assert rk_holder2.while == 0 //Zero value as not specified.
 | ||||
| } | ||||
| 
 | ||||
| struct User2 { | ||||
| mut: | ||||
| 	name string | ||||
| }	 | ||||
| 
 | ||||
| fn test_mutable_fields() { | ||||
| 	mut u := User2{} | ||||
| 	u.name = 'Peter' | ||||
| 	assert u.name == 'Peter' | ||||
| }	 | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ const ( | |||
| 
 | ||||
| fn init_os_args(argc int, argv &byteptr) []string { | ||||
| 	mut args := []string | ||||
| 	for i := 0; i < argc; i++ { | ||||
| 	for i in 0 .. argc { | ||||
| 		args << string(argv[i]) | ||||
| 	}		 | ||||
| 	return args | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue