1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: error with *expr if not a pointer (#6211)

This commit is contained in:
Nick Treleaven 2020-08-24 16:19:17 +01:00 committed by GitHub
parent 60eedc2fc3
commit acc5c95f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 4 deletions

View File

@ -2453,8 +2453,14 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
if node.op == .amp && !right_type.is_ptr() {
return right_type.to_ptr()
}
if node.op == .mul && right_type.is_ptr() {
return right_type.deref()
if node.op == .mul {
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 {
c.error('operator ~ only defined on int types', node.pos)

View File

@ -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
| ^

View File

@ -0,0 +1,6 @@
a := 1
_ = *a
a <- 4
_ = ~true
_ = !4

View File

@ -63,7 +63,7 @@ pub fn resolve_addr(addr string, family SocketFamily, typ SocketType) ?Addr {
sport := '$port'
// This might look silly but is reccomended by MSDN
// This might look silly but is recommended by MSDN
$if windows {
socket_error(0-C.getaddrinfo(address.str, sport.str, &hints, &info))?
} $else {
@ -71,4 +71,4 @@ pub fn resolve_addr(addr string, family SocketFamily, typ SocketType) ?Addr {
}
return new_addr(*info.ai_addr, address, port)
}
}