checker: error with `*expr` if not a pointer (#6211)
parent
60eedc2fc3
commit
acc5c95f0d
|
@ -2453,8 +2453,14 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
||||||
if node.op == .amp && !right_type.is_ptr() {
|
if node.op == .amp && !right_type.is_ptr() {
|
||||||
return right_type.to_ptr()
|
return right_type.to_ptr()
|
||||||
}
|
}
|
||||||
if node.op == .mul && right_type.is_ptr() {
|
if node.op == .mul {
|
||||||
return right_type.deref()
|
if right_type.is_ptr() {
|
||||||
|
return right_type.deref()
|
||||||
|
}
|
||||||
|
if !right_type.is_pointer() {
|
||||||
|
s := c.table.type_to_str(right_type)
|
||||||
|
c.error('prefix operator `*` not defined for type `$s`', node.pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if node.op == .bit_not && !right_type.is_int() && !c.pref.translated {
|
if node.op == .bit_not && !right_type.is_int() && !c.pref.translated {
|
||||||
c.error('operator ~ only defined on int types', node.pos)
|
c.error('operator ~ only defined on int types', node.pos)
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
vlib/v/checker/tests/prefix_err.v:2:5: error: prefix operator `*` not defined for type `int`
|
||||||
|
1 | a := 1
|
||||||
|
2 | _ = *a
|
||||||
|
| ^
|
||||||
|
3 | a <- 4
|
||||||
|
4 |
|
||||||
|
vlib/v/checker/tests/prefix_err.v:3:1: error: cannot push on non-channel `int`
|
||||||
|
1 | a := 1
|
||||||
|
2 | _ = *a
|
||||||
|
3 | a <- 4
|
||||||
|
| ^
|
||||||
|
4 |
|
||||||
|
5 | _ = ~true
|
||||||
|
vlib/v/checker/tests/prefix_err.v:5:5: error: operator ~ only defined on int types
|
||||||
|
3 | a <- 4
|
||||||
|
4 |
|
||||||
|
5 | _ = ~true
|
||||||
|
| ^
|
||||||
|
6 | _ = !4
|
||||||
|
vlib/v/checker/tests/prefix_err.v:6:5: error: ! operator can only be used with bool types
|
||||||
|
4 |
|
||||||
|
5 | _ = ~true
|
||||||
|
6 | _ = !4
|
||||||
|
| ^
|
|
@ -0,0 +1,6 @@
|
||||||
|
a := 1
|
||||||
|
_ = *a
|
||||||
|
a <- 4
|
||||||
|
|
||||||
|
_ = ~true
|
||||||
|
_ = !4
|
|
@ -63,7 +63,7 @@ pub fn resolve_addr(addr string, family SocketFamily, typ SocketType) ?Addr {
|
||||||
|
|
||||||
sport := '$port'
|
sport := '$port'
|
||||||
|
|
||||||
// This might look silly but is reccomended by MSDN
|
// This might look silly but is recommended by MSDN
|
||||||
$if windows {
|
$if windows {
|
||||||
socket_error(0-C.getaddrinfo(address.str, sport.str, &hints, &info))?
|
socket_error(0-C.getaddrinfo(address.str, sport.str, &hints, &info))?
|
||||||
} $else {
|
} $else {
|
||||||
|
@ -71,4 +71,4 @@ pub fn resolve_addr(addr string, family SocketFamily, typ SocketType) ?Addr {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_addr(*info.ai_addr, address, port)
|
return new_addr(*info.ai_addr, address, port)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue