v.checker: allow assigning pointers to fn variables (fix vinix compilation)
parent
afeb1525a1
commit
7143b8ab37
|
@ -4023,11 +4023,14 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||
// Do not allow `a := 0; b := 0; a = &b`
|
||||
if !is_decl && left is ast.Ident && !is_blank_ident && !left_type.is_real_pointer()
|
||||
&& right_type.is_real_pointer() {
|
||||
left_sym := c.table.get_type_symbol(left_type)
|
||||
if left_sym.kind != .function {
|
||||
c.warn(
|
||||
'cannot assign a reference to a value (this will be an error soon) left=${c.table.type_str(left_type)} $left_type.is_ptr() ' +
|
||||
'right=${c.table.type_str(right_type)} $right_type.is_real_pointer() ptr=$right_type.is_ptr()',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
node.left_types << left_type
|
||||
match mut left {
|
||||
ast.Ident {
|
||||
|
|
|
@ -51,3 +51,12 @@ fn test_fn_assignment_array() {
|
|||
assert a[0] == 12
|
||||
assert a[1] == 10
|
||||
}
|
||||
|
||||
fn test_fn_variables_can_be_assigned_pointers() {
|
||||
mut fn_ptr := fn (_ voidptr, _ u64) {}
|
||||
// println(voidptr(fn_ptr))
|
||||
assert fn_ptr != voidptr(0)
|
||||
fn_ptr = voidptr(0)
|
||||
// aprintln(voidptr(fn_ptr))
|
||||
assert fn_ptr == voidptr(0)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue